-1

how can i add field in serializer... This field is not in model no more details thank you

The Serializer

A APIView

ça me renvoie une erreur "Got AttributeError when attempting to get a value for field etat_civil on serializer Serializer_Professeur_Assistant. The serializer field might be named incorrectly and not match any attribute or key on the DescPersonne_Prod instance. Original exception text was: 'DescPersonne_Prod' object has no attribute 'etat_civil'."

Msaidai11
  • 9
  • 1
  • 2
    Please include *code*, not *images of code*: see [*Why not upload images of code errors when asking a question*](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). [edit] the question and include code fragments. – Willem Van Onsem Jun 24 '23 at 08:04

1 Answers1

0

First of all, I can see your field name etat_civil is duplicated for both ChoiceField and CharField. Make sure you make two of them have different field name to avoid collision.

Second, the way that you creating ChoiceField is wrong. I don't know about the version of djangorestframework you are using, but if you are using version more than 3.6.3, then you may refer to this post. In this case of your code, SerializerMethodField could be the best option for showing your customizing data.

Apensia
  • 70
  • 9