Commit 17b4e24a authored by Skia's avatar Skia

Small club update

parent 2f2d5292
Pipeline #660 failed with stage
in 3 minutes and 23 seconds
# -*- 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),
),
]
......@@ -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 ""
......
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment