Small club update

This commit is contained in:
Skia 2016-12-29 00:42:26 +01:00
parent 2f2d5292de
commit 17b4e24aaa
3 changed files with 25 additions and 7 deletions

View File

@ -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),
),
]

View File

@ -143,7 +143,7 @@ class Membership(models.Model):
""" """
user = models.ForeignKey(User, verbose_name=_('user'), related_name="memberships", null=False, blank=False) 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) 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) end_date = models.DateField(_('end date'), null=True, blank=True)
role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()), role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()),
default=sorted(settings.SITH_CLUB_ROLES.items())[0][0]) 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(): 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')) 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): def __str__(self):
return self.club.name+' - '+self.user.username+' - '+str(settings.SITH_CLUB_ROLES[self.role])+str( 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 "" " - "+str(_('past member')) if self.end_date is not None else ""

View File

@ -99,7 +99,10 @@ class ClubMemberForm(forms.ModelForm):
required_css_class = 'required' required_css_class = 'required'
class Meta: class Meta:
model = Membership 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) user = AutoCompleteSelectField('users', required=True, label=_("Select user"), help_text=None)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):