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 rest_framework import viewsets, mixins, status | |
from rest_framework.authentication import TokenAuthentication | |
from rest_framework.permissions import IsAuthenticated | |
# Create your views here. | |
from core.models import House | |
from rental import serializers | |
class HouseViewSet(viewsets.ModelViewSet): |
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.models import query | |
from rest_framework import serializers | |
from core.models import House | |
class HouseSerializer(serializers.ModelSerializer): | |
"""Serializer for the House ad object""" | |
options = serializers.PrimaryKeyRelatedField( | |
queryset=Options.objects.all() | |
) |
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 test | |
from django.test import TestCase | |
from django.urls import reverse | |
from django.contrib.auth import get_user_model | |
from rest_framework import status | |
from rest_framework.test import APIClient | |
from core.models import House |
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.test import TestCase | |
from django.contrib.auth import get_user_model | |
from core import models | |
class ModelTests(TestCase): | |
def test_house_title_str(self): | |
"""Test the House string representation""" | |
house = models.House.objects.create( | |
name='2 rooms appartment downtown Toronto' |
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
class House(models.Model): | |
"""House object""" | |
STATUS_CHOICES = ( | |
('review', 'Review'), | |
('published', 'Published') | |
) | |
title = models.CharField(max_length=255) | |
price = models.DecimalField(max_digits=5, decimal_places=2) | |
description = models.TextField(blank=True) | |
publish = models.DateTimeField(default=timezone.now) |
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, |
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
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
<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
from django import forms | |
class UploadForm(forms.Form): | |
file = forms.FileField(widget=forms.FileInput(attrs={ | |
'id': 'file_id' | |
})) |
NewerOlder