Django Rest Framework Doesn't Display Value In Put Form
Yesterday I posted a question and found a solution to that problem. The solution however caused another issue. Please take a look at the question, so I don't have to duplicate the
Solution 1:
I worked out another way which seemed to be working fine for me. This was to define a class field for the serializer outside the class:
classSpeciesSerializer(serializers.HyperlinkedModelSerializer):
classMeta:
model = Speciesfields= (
'url', 'id', 'canonical_name', 'slug', 'species', 'genus',
'subfamily', 'family', 'order','class', 'phylum',
'ncbi_id', 'ncbi_taxonomy',
)
read_only_fields = ('slug',)
extra_kwargs = {
'url': {'lookup_field': 'slug'}
}
SpeciesSerializer._declared_fields["class"] = serializers.CharField(source="class_name")
After that both Raw Data and HTML Form look fine:
Post a Comment for "Django Rest Framework Doesn't Display Value In Put Form"