Let's say we have model:
class CompanySource(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE, related_name='company_source')
source = models.CharField(max_length=1500)
and we want to have seralizer for it and we use HyperlinkedModelSerializer
it looks like this
class CompanySourceSerializer(serializers.HyperlinkedModelSerializer):
def create(self, validated_data):
return CompanySource.objects.create(**validated_data)
class Meta:
model = CompanySource
fields = ['id', 'company', 'source']
is it required to set source = serializers.CharField(max_length=1500)
inside Serliazer and what does it contribute to? Thank you
question from:
https://stackoverflow.com/questions/65937772/django-rest-framework-do-serializer-require-fields-to-be-specified 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…