Django Rest Framework partial=True not working #8180
Unanswered
schienieder
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am a beginner in Django & DRF and I have a very dumb problem with my project, in which it doesn't allow me to do partial update. I am using generic views (UpdateAPIView) and I have been stuck with it for 2 weeks now.
It allows me to update, however I have to fill every field but what I want to do is to pop email & mobile number if they are the same as the stored value in the database.
Hoping someone might help and thank you in advance.
Model:
`
class BusinessPartner(models.Model):
first_name = models.CharField(max_length=150)
last_name = models.CharField(max_length=150)
mobile_number = models.CharField(max_length=150, unique=True)
email = models.EmailField(max_length=150, unique=True)
business_name = models.CharField(max_length=255, blank=True)
type_of_business = models.CharField(max_length=150, blank=True)
street_address = models.CharField(max_length=255, blank=True)
city = models.CharField(max_length=150, blank=True)
state_province = models.CharField(max_length=150, blank=True)
postal_zip = models.IntegerField(null=True, blank=True)
services_offered = models.TextField(null=True, blank=True)
account = models.ForeignKey(Account, on_delete=models.CASCADE)
`
Serializer:
`
class BusinessPartnerSerializer(serializers.ModelSerializer):
class Meta:
model = BusinessPartner
fields = [
"id",
"first_name",
"last_name",
"mobile_number",
"email",
"business_name",
"type_of_business",
"street_address",
"city",
"state_province",
"postal_zip",
"services_offered",
"account",
]
extra_kwargs = {"id": {"read_only": True}}
`
View:
`
class UpdatePartnerProfileView(generics.UpdateAPIView):
permission_classes = [IsAuthenticated]
serializer_class = BusinessPartnerSerializer
queryset = BusinessPartner.objects.all()
`
Beta Was this translation helpful? Give feedback.
All reactions