Answered step by step
Verified Expert Solution
Question
1 Approved Answer
models.py from django.db import models from django.contrib.auth.models import AbstractUser from django.core.validators import MinLengthValidator, MaxLengthValidator class User ( AbstractUser ) : phone _ number = models.CharField
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import MinLengthValidator, MaxLengthValidator
class UserAbstractUser:
phonenumber models.CharFieldmaxlength uniqueTrue, validatorsMinLengthValidator MaxLengthValidator
email models.EmailFieldblankTrue
groups models.ManyToManyField
'auth.Group',
relatedname'customuserset', # Add a unique relatedname
blankTrue,
helptext'The groups this user belongs to
verbosename'groups',
userpermissions models.ManyToManyField
'auth.Permission',
relatedname'customuserset', # Add a unique relatedname
blankTrue,
helptext'Specific permissions for this user.
verbosename'user permissions',
def strself:
return self.username
class ContactmodelsModel:
user models.ForeignKeyUser ondeletemodels.CASCADE
name models.CharFieldmaxlength
phonenumber models.CharFieldmaxlength
def strself:
return self.name
class SpamReportmodelsModel:
reporter models.ForeignKeyUser ondeletemodels.CASCADE
phonenumber models.CharFieldmaxlength
def strself:
return self.phonenumber
serializers.py
from restframework import serializers
from models import User, Contact, SpamReport
class UserSerializerserializersModelSerializer:
class Meta:
model User
fields id 'username', 'phonenumber', 'email'
class ContactSerializerserializersModelSerializer:
class Meta:
model Contact
fields id 'user', 'name', 'phonenumber'
class SpamReportSerializerserializersModelSerializer:
class Meta:
model SpamReport
fields id 'reporter', 'phonenumber'
urls.py
from django.urls import path, include
from restframework.routers import DefaultRouter
from views import UserViewSet, ContactViewSet, SpamReportViewSet
router DefaultRouter
router.registerrusers UserViewSet
router.registerrcontacts ContactViewSet
router.registerrspamreports SpamReportViewSet
urlpatterns
path includerouterurls
views.py
from restframework import viewsets, filters
from models import User, Contact, SpamReport
from serializers import UserSerializer, ContactSerializer, SpamReportSerializer
class UserViewSetviewsetsModelViewSet:
queryset User.objects.all
serializerclass UserSerializer
filterbackends filtersSearchFilter
searchfields username 'phonenumber'
class ContactViewSetviewsetsModelViewSet:
queryset Contact.objects.all
serializerclass ContactSerializer
class SpamReportViewSetviewsetsModelViewSet:
queryset SpamReport.objects.all
serializerclass SpamReportSerializer
Check the above code for plagarism and if plagarism is found redo the code that will give plagarism less than
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started