K
K
kieko2021-06-11 12:31:28
Django
kieko, 2021-06-11 12:31:28

How to add a link to another model in relation to many-to-many when creating an object??

there is a model:

Class Meeting(models.Model):
    name = models.CharField(max_length = 255)


Class Group(models.Model):
    name = models.CharField(max_length = 255)
    meeting  = models.ManyToManyField(Meeting ,through=GroupMeeting)


GroupMeeting(models.Model):
    meeting = models.ForeignKey(Meeting, on_delete=models.CASCADE)
    group = models.ForeignKey(Group, on_delete=models.CASCADE)


How to Meeting assign a link to Group??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mr_forlife, 2021-06-12
@kieko

group = Group.objects.create(name='some_name_group')
meeting = Meeting.objects.create(name='some_meeting_name')
group.meeting.add(meeting)

details here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question