-1

I have model

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

How create model GroupMeeting witch can be connected with many meetings and one meeting can have only one GroupMeeting

class GroupMeeting ( models . Model ):
    meeting = models . ForeignKey ( Meeting , on_delete = models.SET_NULL 
    group_id = models . IntegerField () 
    name = models . CharField ( max_length = 255 )

in this case I have opposite situation many GroupMeeting have one Meeting

How to do it without changing Meeting class !!

tarp20
  • 635
  • 1
  • 6
  • 13
  • Why is it a requirement to not change the `Meeting` class…? – deceze Jun 10 '21 at 08:57
  • 1
    Without changing `Meeting`, you can not. Check https://stackoverflow.com/questions/6928692/how-to-express-a-one-to-many-relationship-in-django – Henri Jun 10 '21 at 08:59

1 Answers1

2

You've got your ForeignKey the wrong way round. a ForeignKey is many-to-one so if you had

group_meeting = models.ForeignKey(GroupMeeting , on_delete=models.SET_NULL)

In Meeting class then you have your desired result

Henty
  • 603
  • 2
  • 7