I have extended the Django User model creating a 1-to-1 dependency with the class Profile. There will be many profiles playing in the same Community. And a Profile can be playing in different Communities at the same time. I did this with a Many-to-Many field "members" in the Community Model. This is shown below. (I have reduced the irrelevant code)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
# Extend Users Here
class Community(models.Model):
username = models.CharField(max_length=100)
password = models.CharField(max_length=50)
members = models.ManyToManyField(Profile, through='Membership')
def get_members(self):
return "\n".join([str(m) for m in self.members.all()])
class Membership(models.Model):
community = models.ForeignKey(Community, on_delete=models.CASCADE)
player = models.ForeignKey(Profile, on_delete=models.CASCADE)
When a new profile is created I would like it to be inmediately associated with a Community.
Therefore, in the user registration form I would like to ask him if he wants to join an existing community or create a new one.
I believe I need something as "Multiple Form" but I would appreciate help in what exactly do I need and how I can look for information about it.
Thanks!
