Skip to content

Instantly share code, notes, and snippets.

View godfather68's full-sized avatar

Farel Ellely godfather68

View GitHub Profile
@godfather68
godfather68 / urls.py
Created July 12, 2021 14:00
main urls for the rentals project
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):
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()
)
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
@godfather68
godfather68 / tests.py
Created July 9, 2021 21:03
Testing Models
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'
@godfather68
godfather68 / models.py
Last active July 9, 2021 21:00
models.py for rental service API.
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)
<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,
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 = '/'
import pytesseract # ======= > Add
try:
from PIL import Image
except:
import Image
# Create your views here.
class HomeView(FormView):
form_class = UploadForm
<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>
from django import forms
class UploadForm(forms.Form):
file = forms.FileField(widget=forms.FileInput(attrs={
'id': 'file_id'
}))