I'm working on a project where a user can add an event, and another user can enroll themself in that event. I want to add a user's name to the list whenever they enroll in the event.

My model:

class Event(models.Model):

    Topic = CharField
    participants =  # want a field here
                    # which can store
                    # multiple items
                    # that is the name
                    # of the user. So when
                    # the user
                    # registers a
                    # method appends
                    # the user name in this list.
1

There are 1 best solutions below

2
On

You'll want a ManyToManyField to link users to Events:

class Event(models.Model):
    topic = CharField()
    participants = models.ManyToManyField(User)

You can also add a separate "through" table to add extra information about participations:

class Event(models.Model):
    topic = models.CharField()
    participants = models.ManyToManyField(User, through='Participation')


class Participation(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    event = models.ForeignKey(Event, on_delete=models.CASCADE)
    date_joined = models.DateTimeField(auto_now_add=True)