This file contains 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 permissions | |
class IsAuthenticatedAndOwnerOrDeny(permissions.BasePermission): | |
def has_permission(self, request, view): | |
# check if the user is authenticated | |
return self.request.user.is_authenticated() | |
def has_object_permission(self, request, view, obj): | |
# check if the user is the owner of the inference object |
This file contains 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 | |
from django.contrib.auth.models import User | |
class SentimentAnalysisInference(models.Model): | |
user = models.OneTOneField(User,on_delete=models.CASCADE) | |
text = models.TextField() | |
result = models.CharField(max_length=255) | |
This file contains 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 serializers | |
from .models import Review | |
class ReviewSerializer(serializers.Serializer): | |
class Meta : | |
model = Review | |
fields = ['username','content'] | |
# to validate any field override the function validate_<field> | |
def validate_username(self,value): |
This file contains 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 | |
class Review(models.Model): | |
username = models.CharField(max_length=255) | |
content = models.TextField() | |
def __str__(self): | |
return '{username} => {content}'.format(username=self.username,content=self.content) | |
This file contains 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
# ... | |
# installed app | |
INSTALLED_APPS = [ | |
# ... | |
'Inference', | |
This file contains 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 django.urls import path | |
from rest_framework_jwt.views import obtain_jwt_token,refresh_jwt_token | |
from django.conf.urls.static import static | |
from django.conf import settings | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('',include('infrence.urls')), |
This file contains 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 Inference | |
from keras.preprocessing import image | |
from keras.models import model_from_json | |
import numpy as np | |
class InferenceForm(forms.ModelForm): | |
class Meta : | |
model = Inference |
This file contains 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
<html> | |
<head> | |
<title>Update Inference</title> | |
</head> | |
<body> | |
<div> | |
<form method='POST' enctype="multipart/form-data"> {% csrf_token %} | |
{{form.media}} | |
{{form.as_p}} | |
<input type="submit" value="update" > |
This file contains 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
<html> | |
<head> | |
<title>Delete Inference</title> | |
</head> | |
<body> | |
<h3> Are you sure about deleting {{object.title}} product</h3> | |
<form action='POST' >{% csrf_token %} | |
<input type='submit' value='sure' /> or <a href='/' >forget</a> | |
</form> | |
</body> |
This file contains 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
<html> | |
<head> | |
<title>create Inference</title> | |
</head> | |
<body> | |
<div> | |
<form method='POST' enctype="multipart/form-data"> {% csrf_token %} | |
{{form.media}} | |
{{form.as_p}} |