Django modeling - need advise on Guest, Host, Invitations relation model

Viewed 40

I have the following case, which I can't turn into Django models on my own, hence asking the community:

A party Host sends out invitations for an Event to multiple Guests and wants to track whom they send Invitations. A Host may host different Events and send out an invitation for each Event to the same Guest.

Guest needs to track his invites too. I.e. can ignore or accept an invitation, and be able to see their history of invitations.

Host needs to track down responses too, i.e. view who responded for each Event.

So, I have so far the following model (simplified here):

class Host(models.Model):
    name = models.CharField(max_length=20)


class Guest(models.Model):
    name = models.CharField(max_length=20)

class Event(models. Model):
    name = models.CharField(max_length=20)
one)
    date = models.DateField()

    host = models.ForeignKey(Host, 
        related_name="invatations"
    )

    invitations = models.ManyToManyField(Guest,
        related_name="invatations",    
    )

So this gives me:

Host can access a list of invited Guests.

Guest can access their invitations via a related name.

But I can't figure out how to make invite management by Guest and Host separately. I.e. they should have their own lists, it seems. I.e. if a guest may trash an invite, a Host still needs to see this invite as sent out on his side.

Should I just add fields "responded", "ignored" to the Event and filter for them for a Guest and a Host respectively?

Or need to add new classes for a received invite and response, for example?

Or do something different?

1 Answers

Ok, I came up with the following model.

I made a separate class Invitation, which refers to an Event and a Guest. invitations are removed from Event class. Whether an invitatation is accepted is in Invitation.status.

class Event(models. Model):
    name = models.CharField(max_length=20)
one)
    date = models.DateField()

    host = models.ForeignKey(Host, 
        related_name="invatations"
    )

class Invitation(models.Model):
    guest = models.ForeighnKey(Guest)

    event = models.ForeighnKey(Event)

    status = models.CharField()

Related