Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

First version of contract model for gyms

Roland Geider3e3ca42bbf0e
diff --git a/wger/gym/migrations/0003_auto_20151003_2008.py b/wger/gym/migrations/0003_auto_20151003_2008.py
new file mode 100644
index 000000000..8eff7b4de
--- /dev/null
+++ b/wger/gym/migrations/0003_auto_20151003_2008.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import datetime
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('gym', '0002_auto_20151003_1944'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Contract',
+ fields=[
+ ('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
+ ('timestamp_created', models.DateTimeField(auto_now_add=True)),
+ ('timestamp_edited', models.DateTimeField(auto_now=True)),
+ ('amount', models.PositiveIntegerField(verbose_name='Amount', default=0)),
+ ('payment', models.CharField(verbose_name='Payment type', default='3', help_text='How often the amount will be charged to the member', choices=[('1', 'Yearly'), ('2', 'Half yearly'), ('3', 'Monthly'), ('4', 'Biweekly'), ('5', 'Weekly'), ('6', 'Daily')], max_length=2)),
+ ('is_active', models.BooleanField(verbose_name='Contract is active', default=True)),
+ ('date_start', models.DateField(verbose_name='Start date', blank=True, default=datetime.date.today, null=True)),
+ ('date_end', models.DateField(verbose_name='End date', blank=True, null=True)),
+ ('email', models.EmailField(verbose_name='Email', blank=True, null=True, max_length=254)),
+ ('zip_code', models.CharField(verbose_name='ZIP code', blank=True, null=True, max_length=10)),
+ ('city', models.CharField(verbose_name='City', blank=True, null=True, max_length=30)),
+ ('street', models.CharField(verbose_name='Street', blank=True, null=True, max_length=30)),
+ ('phone', models.CharField(verbose_name='Phone', blank=True, null=True, max_length=20)),
+ ('profession', models.CharField(verbose_name='Profession', blank=True, null=True, max_length=50)),
+ ('note', models.TextField(verbose_name='Note', blank=True, null=True)),
+ ],
+ options={
+ 'ordering': ['-date_start'],
+ },
+ ),
+ migrations.CreateModel(
+ name='ContractType',
+ fields=[
+ ('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
+ ('name', models.CharField(verbose_name='Name', max_length=25)),
+ ('description', models.TextField(verbose_name='Description', blank=True, null=True)),
+ ('gym', models.ForeignKey(to='gym.Gym', editable=False)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='contract',
+ name='contract_type',
+ field=models.ForeignKey(verbose_name='Contract type', blank=True, null=True, to='gym.ContractType'),
+ ),
+ migrations.AddField(
+ model_name='contract',
+ name='member',
+ field=models.ForeignKey(editable=False, to=settings.AUTH_USER_MODEL, related_name='contract_member'),
+ ),
+ migrations.AddField(
+ model_name='contract',
+ name='user',
+ field=models.ForeignKey(editable=False, to=settings.AUTH_USER_MODEL, related_name='contract_user'),
+ ),
+ ]
diff --git a/wger/gym/models.py b/wger/gym/models.py
index b6c866b00..448039e5d 100644
--- a/wger/gym/models.py
+++ b/wger/gym/models.py
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
import uuid
+import datetime
from django.db import models as m
from django.contrib.auth.models import User
@@ -349,3 +350,192 @@ class UserDocument(m.Model):
trainers in the gym.
'''
return None
+
+
+@python_2_unicode_compatible
+class ContractType(m.Model):
+ '''
+ Model for a contract's type
+
+ A contract type is a user-editable way of enhancing the contract to
+ specify types, such as e.g. 'with personal trainer', 'regular', etc.
+ '''
+
+ gym = m.ForeignKey(Gym,
+ editable=False)
+ '''
+ The gym this contract type belongs to
+ '''
+
+ name = m.CharField(verbose_name=_('Name'),
+ max_length=25)
+ '''
+ The contract type's short name
+ '''
+
+ description = m.TextField(verbose_name=_('Description'),
+ blank=True,
+ null=True)
+ '''
+ Free text field for additional information
+ '''
+
+ def __str__(self):
+ '''
+ Return a more human-readable representation
+ '''
+ return "{}".format(self.name)
+
+
+@python_2_unicode_compatible
+class Contract(m.Model):
+ '''
+ Model for a member's contract in a gym
+ '''
+
+ AMOUNT_TYPE_YEARLY = '1'
+ AMOUNT_TYPE_HALFYEARLY = '2'
+ AMOUNT_TYPE_MONTHLY = '3'
+ AMOUNT_TYPE_BIWEEKLY = '4'
+ AMOUNT_TYPE_WEEKLY = '5'
+ AMOUNT_TYPE_DAILY = '6'
+
+ AMOUNT_TYPE = (
+ (AMOUNT_TYPE_YEARLY, _("Yearly")),
+ (AMOUNT_TYPE_HALFYEARLY, _('Half yearly')),
+ (AMOUNT_TYPE_MONTHLY, _('Monthly')),
+ (AMOUNT_TYPE_BIWEEKLY, _('Biweekly')),
+ (AMOUNT_TYPE_WEEKLY, _('Weekly')),
+ (AMOUNT_TYPE_DAILY, _('Daily')),
+ )
+
+ class Meta:
+ '''
+ Order by time
+ '''
+ ordering = ["-date_start", ]
+
+ user = m.ForeignKey(User,
+ editable=False,
+ related_name='contract_user')
+ '''
+ User that originally created the contract
+ '''
+
+ member = m.ForeignKey(User,
+ editable=False,
+ related_name='contract_member')
+ '''
+ Gym member this contract refers to
+ '''
+
+ timestamp_created = m.DateTimeField(auto_now_add=True)
+ '''
+ Time when the contract was created
+ '''
+
+ timestamp_edited = m.DateTimeField(auto_now=True)
+ '''
+ Last time when the contract was edited
+ '''
+
+ contract_type = m.ForeignKey(ContractType,
+ blank=True,
+ null=True,
+ verbose_name=_('Contract type'))
+ '''
+ Optional type of contract
+ '''
+
+ amount = m.PositiveIntegerField(verbose_name=_('Amount'),
+ default=0)
+ '''
+ The amount to pay
+ '''
+
+ payment = m.CharField(verbose_name=_('Payment type'),
+ max_length=2,
+ choices=AMOUNT_TYPE,
+ default=AMOUNT_TYPE_MONTHLY,
+ help_text=_('How often the amount will be charged to the member'))
+ '''
+ How often the amount will be charged to the member
+ '''
+
+ is_active = m.BooleanField(verbose_name=_('Contract is active'),
+ default=True)
+ '''
+ Flag showing whether the contract is currently active
+ '''
+
+ date_start = m.DateField(verbose_name=_('Start date'),
+ default=datetime.date.today,
+ blank=True,
+ null=True)
+ '''
+ The date when the contract starts
+ '''
+
+ date_end = m.DateField(verbose_name=_('End date'),
+ blank=True,
+ null=True)
+ '''
+ The date when the contract ends
+ '''
+
+ email = m.EmailField(verbose_name=_('Email'),
+ blank=True,
+ null=True)
+ '''The member's email'''
+
+ zip_code = m.CharField(_(u'ZIP code'),
+ max_length=10,
+ blank=True,
+ null=True)
+ '''ZIP code'''
+
+ city = m.CharField(_(u'City'),
+ max_length=30,
+ blank=True,
+ null=True)
+ '''City'''
+
+ street = m.CharField(_(u'Street'),
+ max_length=30,
+ blank=True,
+ null=True)
+ '''Street'''
+
+ phone = m.CharField(verbose_name=_('Phone'),
+ max_length=20,
+ blank=True,
+ null=True)
+ '''Phone number'''
+
+ profession = m.CharField(verbose_name=_('Profession'),
+ max_length=50,
+ blank=True,
+ null=True)
+ '''
+ The member's profession
+ '''
+
+ note = m.TextField(verbose_name=_('Note'),
+ blank=True,
+ null=True)
+ '''
+ Free text note with additional information
+ '''
+
+ def __str__(self):
+ '''
+ Return a more human-readable representation
+ '''
+ return "#{}".format(self.id)
+
+ def get_owner_object(self):
+ '''
+ While the model has a user foreign key, this is editable by all
+ managers in the gym.
+ '''
+ return None