This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from .models import Customer, Request | |
class CreateRequestForm(forms.ModelForm): | |
customer = forms.CharField() | |
def clean(self): # update | |
data = self.cleaned_data.pop('customer') | |
customer, created = Customer.objects.get_or_create(name=data) | |
self.cleaned_data.update({'customer': customer}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
# Create your models here. | |
class Customer(models.Model): | |
name = models.CharField(max_length=50) | |
barcode = models.ImageField(upload_to='barcodes/', blank=True) | |
def __str__(self): | |
return self.name | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
import barcode # additional imports | |
from barcode.writer import ImageWriter | |
from io import BytesIO | |
from django.core.files import File | |
# Create your models here. | |
class Customer(models.Model): | |
name = models.CharField(max_length=50) | |
barcode = models.ImageField(upload_to='barcodes/', blank=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import Customer | |
from import_export import resources | |
from import_export.admin import ImportExportModelAdmin | |
# Register your models here. | |
class CustomerResource(resources.ModelResource): | |
class Meta: | |
model = Customer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.http import JsonResponse | |
from django.views.generic import FormView | |
from .forms import * | |
# Create your views here. | |
class HomeView(FormView): | |
form_class = UploadForm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
class UploadForm(forms.Form): | |
file = forms.FileField(widget=forms.FileInput(attrs={ | |
'id': 'file_id' | |
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style="text-align: center;"> | |
<form enctype="multipart/form-data" id="ocrForm" method="post"> <!-- Do not forget to add: enctype="multipart/form-data" --> | |
{% csrf_token %} | |
{{ form }} | |
<button type="submit" class="btn btn-success">OCRzed</button> | |
</form> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytesseract # ======= > Add | |
try: | |
from PIL import Image | |
except: | |
import Image | |
# Create your views here. | |
class HomeView(FormView): | |
form_class = UploadForm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.decorators.csrf import csrf_exempt | |
import json | |
... | |
# Create your views here. | |
class HomeView(FormView): | |
form_class = UploadForm | |
template_name = 'index.html' | |
success_url = '/' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function(){ | |
function submitFile(){ | |
var fd = new FormData(); | |
fd.append('file', getFile()) | |
$.ajax({ | |
url: "{% url 'process_image' %}", | |
type: "POST", | |
data: fd, | |
processData: false, |