I have the Gammer model that is the User extension and the Competition model. many players can play a competition and a competition can have many players ( ManyToMany
)
class Gammer(User):
competition = models.ManyToManyField(Competition)
puntaje_global = models.IntegerField(default=0)
ranking = models.IntegerField(default=0)
class Competition(models.Model):
name = models.CharField(max_length=50)
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
finish_date = models.DateTimeField(blank=True, null=True)
duration = models.DurationField(blank=True, null=True)
def finish(self):
self.finish_date = timezone.now()
self.save()
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.name
Add in admin.py:
admin.site.register (Gammer)
The admin can visualize competitions of player or assign them competitions:
Now I want the players to choose the competitions they want to subscribe to.
I created GammerForm in forms.py (I do not know if it's correct)
class GammerForm(forms.ModelForm):
competition = forms.ModelMultipleChoiceField(
queryset=models.Competition.objects.all())
class Meta:
model=models.Gammer
fields =('competition', )
How can I continue so that the user from his account can join the competitions and not the admin anymore? That is to say, that all the competences are listed and that the user can subscribe, and if everything goes well the admin could see the competences in which the user joined.