From 17b4e24aaa164789b8e61b575b36e45ae2f50394 Mon Sep 17 00:00:00 2001 From: Skia Date: Thu, 29 Dec 2016 00:42:26 +0100 Subject: [PATCH] Small club update --- club/migrations/0006_auto_20161229_0040.py | 20 ++++++++++++++++++++ club/models.py | 7 +------ club/views.py | 5 ++++- 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 club/migrations/0006_auto_20161229_0040.py diff --git a/club/migrations/0006_auto_20161229_0040.py b/club/migrations/0006_auto_20161229_0040.py new file mode 100644 index 00000000..58a0f676 --- /dev/null +++ b/club/migrations/0006_auto_20161229_0040.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('club', '0005_auto_20161120_1149'), + ] + + operations = [ + migrations.AlterField( + model_name='membership', + name='start_date', + field=models.DateField(verbose_name='start date', default=django.utils.timezone.now), + ), + ] diff --git a/club/models.py b/club/models.py index b3121aaf..3b02be0f 100644 --- a/club/models.py +++ b/club/models.py @@ -143,7 +143,7 @@ class Membership(models.Model): """ user = models.ForeignKey(User, verbose_name=_('user'), related_name="memberships", null=False, blank=False) club = models.ForeignKey(Club, verbose_name=_('club'), related_name="members", null=False, blank=False) - start_date = models.DateField(_('start date')) + start_date = models.DateField(_('start date'), default=timezone.now) end_date = models.DateField(_('end date'), null=True, blank=True) role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()), default=sorted(settings.SITH_CLUB_ROLES.items())[0][0]) @@ -156,11 +156,6 @@ class Membership(models.Model): if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists(): raise ValidationError(_('User is already member of that club')) - def save(self, *args, **kwargs): - if not self.id: - self.start_date = timezone.now() - return super(Membership, self).save(*args, **kwargs) - def __str__(self): return self.club.name+' - '+self.user.username+' - '+str(settings.SITH_CLUB_ROLES[self.role])+str( " - "+str(_('past member')) if self.end_date is not None else "" diff --git a/club/views.py b/club/views.py index 23e0c959..547f8103 100644 --- a/club/views.py +++ b/club/views.py @@ -99,7 +99,10 @@ class ClubMemberForm(forms.ModelForm): required_css_class = 'required' class Meta: model = Membership - fields = ['user', 'role', 'description'] + fields = ['user', 'role', 'start_date', 'description'] + widgets = { + 'start_date': SelectDate + } user = AutoCompleteSelectField('users', required=True, label=_("Select user"), help_text=None) def save(self, *args, **kwargs):