Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Event(models.Model):
- name = models.CharField(max_length=200)
- type = models.ForeignKey("Event_type", blank=True, null=True, on_delete=models.SET_NULL)
- date = models.DateTimeField(blank=True, null=True, default=now())
- duration = models.IntegerField(blank=True, null=True, help_text="la durata va espressa in minuti")
- note = RichTextField(blank=True, null=True)
- result = RichTextField(blank=True, null=True)
- participants = models.ManyToManyField(UserProfile, through='Subscriber', through_fields=('event', 'member'))
- @classmethod
- def subscribe(cls, current_user, event):
- event.participants.add(current_user)
- @classmethod
- def unsubscribe(cls, current_user, event):
- event.participants.remove(current_user)
- class Subscriber (models.Model):
- '''
- identifica i membri che si sono iscritti a uno specifico evento associandoli al loro team default.
- il team può essere successivamente cambiato ai fini dell'evento
- qui si inserisco i punti ottenuti, il tipo di premio viene specificato nelle caratteristiche dell'evento
- '''
- event = models.ForeignKey("Event", on_delete=models.CASCADE)
- member = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name="member", blank=True, null=True)
- award = models.IntegerField(default='0')
- party = models.ForeignKey(Party, on_delete=models.CASCADE, blank=True, null=True)
- party_leader = models.BooleanField(default=False)
- creation_date = models.DateTimeField(auto_now=False, auto_now_add=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement