add docstring for entry

This commit is contained in:
Pierre-antoine Comby 2020-04-06 12:32:44 +02:00
parent 61b32f9aec
commit 7e0aac0125
1 changed files with 8 additions and 3 deletions

View File

@ -104,6 +104,12 @@ class Activity(models.Model):
class Entry(models.Model): class Entry(models.Model):
"""
Register the entry of someone:
- a member with a :model:`note.NoteUser`
- or a :model:`activity.Guest`
In the case of a Guest Entry, the inviter note is also save.
"""
activity = models.ForeignKey( activity = models.ForeignKey(
Activity, Activity,
on_delete=models.PROTECT, on_delete=models.PROTECT,
@ -131,8 +137,7 @@ class Entry(models.Model):
class Meta: class Meta:
unique_together = (('activity', 'note', 'guest', ), ) unique_together = (('activity', 'note', 'guest', ), )
def save(self, force_insert=False, force_update=False, using=None, def save(self, *args,**kwargs):
update_fields=None):
qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest) qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest)
if qs.exists(): if qs.exists():
@ -146,7 +151,7 @@ class Entry(models.Model):
if self.note.balance < 0: if self.note.balance < 0:
raise ValidationError(_("The balance is negative.")) raise ValidationError(_("The balance is negative."))
ret = super().save(force_insert, force_update, using, update_fields) ret = super().save(*args,**kwargs)
if insert and self.guest: if insert and self.guest:
GuestTransaction.objects.create( GuestTransaction.objects.create(