Home > other >  DRF framework many-to-many associations in the field holds many - to - the things
DRF framework many-to-many associations in the field holds many - to - the things

Time:10-17


DRF framework associated field data error
Error details
Here insert picture description

User=super (). The create (validated_data)
# the user=user. Objects. The create validated_data (* *)
Annotation for the cause of the error, not annotation is the solution,
Reason: in the frame of the DRF, when to have a many-to-many association columns to add data model classes, not directly with the model name of the class. Objects. The create (), the create method on the need to use DRF bring ModelSerializerl class, because the method inner packing to modify the value of the given many-to-many associations field function (many-to-many associations field modification is to modify the table in the middle of the data, not the current table or table) was associated with the current table.
Such as: User model classes and class Group model is a many-to-many relationship, associated fields defined in the User model class, and the actual deposit their relationship is to the middle, in table users_user_groups when modified so, is to modify the table data among them,
  • Related