Question

i'm using djangorestframework. the models one meeting could have many participates. So i tried to use ManytoManyField of django:

class Meeting(models.Model):
    name=models.CharField(max_length=100)
    participates=models.ManyToManyField(Person)

by python manager.py sqlall XXX the DB tables are:

CREATE TABLE "OA_meeting_participates" (

    "id" integer NOT NULL PRIMARY KEY,
    "meeting_id" integer NOT NULL,
    "person_id" integer NOT NULL REFERENCES "OA_person" ("id"),
    UNIQUE ("meeting_id", "person_id")
)
;
CREATE TABLE "OA_meeting" (

    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(100) NOT NULL,
)

the problems comes: when i create a meeting by selecting some persons, server response 'participates' is an invalid keyword argument for this function. since OA_meeting does not have participates field. so how to solve it?

Was it helpful?

Solution

see the docs on manytomany fields. You need to create the meeting and person objects separately first, and then do meeting.partcipates.add(person)

(btw, i think the word you are looking for is participANts)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top