Я новичок в django.поэтому мне нужно написать метод Post для получения информации о клиенте с помощью customermobile (имя пользователя) и customerPassword (пароль).Я прочитал концепцию фильтра, но мне не повезло.
models.py
class Customer(models.Model):
Status = Choices(
(0, 'Deleted'),
(1, 'disabled'),
(2, 'active'),
)
customerID = models.AutoField(primary_key=True)
companyID = models.ForeignKey(Company, on_delete=models.CASCADE)
firstName = models.CharField(max_length=200, null=False)
lastName = models.CharField(max_length=200, null=True)
customermobile = models.CharField(max_length=20, null=False)
customerpassword = models.CharField(max_length=20, validators=[MinLengthValidator(8)], null=False)
customeremail = models.CharField(max_length=1000, null=True)
tocken = models.CharField(max_length=35, default=str(uuid.uuid4().hex))
createdBy = models.IntegerField(null=False)
createdAt = models.DateTimeField(null=False, auto_now=True)
status = models.IntegerField(choices=Status, default=2)
updatedBy = models.IntegerField(null=True)
updatedAt = models.DateTimeField(null=True, auto_now=True)
def __str__(self):
return "{}".format(self.firstName)
Serializers.py
class CustomerSerializer(serializers.ModelSerializer):
class Meta:
model = customer
fields = ('companyID', 'firstName', 'lastName', 'customermobile', 'customerpassword', 'customeremail', 'tocken', 'createdBy', 'createdAt', 'status', )
read_only_fields = ('createdAt',)
views.py
class CustomerList(APIView):
"""List all Customer or create the new customer"""
def post(self, request, format=None):
customerSerializer = CustomerSerializer(data=request.POST)
if customerSerializer.is_valid():
customerSerializer.save()
return Response(customerSerializer.data, status=status.HTTP_201_CREATED)
return Response(customerSerializer.errors, status=status.HTTP_400_BAD_REQUEST)
class CustomerFilter(django_filters.FilterSet):
class Meta:
model = Customer
fields = ['customermobile', 'customerpassword']
class Login(APIView):
def post(self, request, format=None):
customer = Customer.objects.all()
customeFil = CustomerFilter(request.POST, queryset=customer)
Если кто-нибудь знает решение, пожалуйста, дайте мне знать здесь.Спасибо