Create an Association model

The previous fk and m2m to groups representing associations are replaced by a
proper link to the Association table.
This commit is contained in:
Martin Pépin 2017-06-24 22:35:25 +01:00
parent b68590ffd7
commit a9e6ef6c5c
2 changed files with 93 additions and 2 deletions

View file

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11b1 on 2017-06-24 21:21
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
def create_apps(apps, schema_editor):
Association = apps.get_model("gestion", "Association")
Group = apps.get_model("auth", "Group")
cof_m, _ = Group.objects.get_or_create(name="cof_members")
cof_b, _ = Group.objects.get_or_create(name="cof_buro")
bds_m, _ = Group.objects.get_or_create(name="bds_members")
bds_b, _ = Group.objects.get_or_create(name="bds_buro")
Association.objects.bulk_create([
Association(id=1, name="COF", staff_group=cof_b, members_group=cof_m),
Association(id=2, name="BDS", staff_group=bds_b, members_group=bds_m),
])
class Migration(migrations.Migration):
dependencies = [
('auth', '0008_alter_user_username_max_length'),
('gestion', '0004_verbose_names'),
]
operations = [
migrations.CreateModel(
name='Association',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=30, verbose_name="nom de l'association")),
('members_group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='member_groups', to='auth.Group', verbose_name='groupe des membres')),
('staff_group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='staff_groups', to='auth.Group', verbose_name='groupe des membre du bureau')),
],
options={
'verbose_name': 'association',
'verbose_name_plural': 'associations',
},
),
migrations.RunPython(create_apps, migrations.RunPython.noop),
migrations.RemoveField(
model_name='club',
name='associations',
),
migrations.AddField(
model_name='club',
name='association',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, related_name='clubs', to='gestion.Association', verbose_name='association'),
preserve_default=False,
),
migrations.AlterField(
model_name='event',
name='associations',
field=models.ManyToManyField(related_name='events', to='gestion.Association', verbose_name='associations'),
),
]

View file

@ -66,6 +66,31 @@ def post_delete_user(sender, instance, *args, **kwargs):
instance.user.delete()
class Association(models.Model):
name = models.CharField(_("nom de l'association"), max_length=30)
staff_group = models.ForeignKey(
Group,
on_delete=models.PROTECT,
related_name="staff_groups",
blank=True, null=True,
verbose_name=_("groupe des membre du bureau"),
)
members_group = models.ForeignKey(
Group,
on_delete=models.PROTECT,
related_name="member_groups",
blank=True, null=True,
verbose_name=_("groupe des membres"),
)
class Meta:
verbose_name = _("association")
verbose_name_plural = _("associations")
def __str__(self):
return self.name
# ---
# Clubs
# ---
@ -81,7 +106,12 @@ class Club(models.Model):
(COURSE, _("Au cours"))
]
associations = models.ManyToManyField(Group, related_name="clubs")
association = models.ForeignKey(
Association,
on_delete=models.PROTECT,
related_name="clubs",
verbose_name=_("association"),
)
name = models.CharField(_("nom"), max_length=200, unique=True)
description = models.TextField("description", blank=True)
members = models.ManyToManyField(
@ -139,7 +169,7 @@ class Location(models.Model):
class Event(models.Model):
associations = models.ManyToManyField(
Group,
Association,
related_name="events",
verbose_name=_("associations"),
)