I have the following view:
class CampaignUpdate(generics.RetrieveUpdateAPIView):
queryset = Campaign.objects.all()
serializer_class = CampaignSerializer
permission_classes = [CampaignDetailPermission]
lookup_field = 'cid'
And I have the following test function:
def test_update_campaign(self):
request = self.factory.put(f'/', {'name': 'Updated Campaign'})
force_authenticate(request, user=self.merchant)
response = CampaignUpdate.as_view()(request, cid=self.campaign.cid)
# Check that the response status code is 200 (OK)
print(response.data)
self.assertEqual(response.status_code, 200)
# Check that the campaign was updated in the database
self.assertEqual(Campaign.objects.get(cid=self.campaign.cid).name, 'Updated Campaign')
And I am getting the following error:
System check identified 4 issues (0 silenced).
..........{'shop': [ErrorDetail(string='This field is required.', code='required')]}
shop
field is required for creation but i do not want to update this field everytime I update some other field.
How can I make it optional for update or readonly after creation?
In case, you need to see serializer:
class CampaignSerializer(serializers.ModelSerializer):
class Meta:
model = Campaign
fields = '__all__'