|
@@ -3,21 +3,21 @@ from django.contrib.auth.models import User
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
|
-
|
|
|
from banking.models import Payment
|
|
|
|
|
|
|
|
|
class Adherent(models.Model):
|
|
|
limit = models.Q(app_label='auth', model='user') \
|
|
|
| models.Q(app_label='adhesions', model='corporation')
|
|
|
- id = models.IntegerField(verbose_name='Numéro d’adhérent', primary_key=True)
|
|
|
+ id = models.AutoField(verbose_name='Numéro d’adhérent', primary_key=True, editable=True)
|
|
|
adherent_type = models.ForeignKey(ContentType, on_delete=models.CASCADE,
|
|
|
limit_choices_to=limit, verbose_name='Type d’adhérent')
|
|
|
adherent_id = models.PositiveIntegerField(verbose_name='ID')
|
|
|
adherent = GenericForeignKey('adherent_type', 'adherent_id')
|
|
|
- contribution = models.ForeignKey(Payment, on_delete=models.CASCADE,
|
|
|
- null=True, blank=True, related_name='adherent',
|
|
|
- verbose_name='Cotisation')
|
|
|
+ contribution = GenericRelation(Payment,
|
|
|
+ content_type_field='reason_type',
|
|
|
+ object_id_field='reason_id',
|
|
|
+ related_query_name='adherent')
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'adhérent'
|
|
@@ -51,8 +51,6 @@ class Profile(AdhesionMixin, models.Model):
|
|
|
phone_number = models.CharField(max_length=16, blank=True, default='',
|
|
|
verbose_name='Numéro de téléphone')
|
|
|
address = models.TextField(blank=True, default='', verbose_name='Adresse')
|
|
|
- adhesions = GenericRelation(Adherent, content_type_field='adherent_type',
|
|
|
- object_id_field='adherent_id', related_query_name='users')
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'profil'
|
|
@@ -69,7 +67,7 @@ class Corporation(AdhesionMixin, models.Model):
|
|
|
adhesions = GenericRelation(Adherent,
|
|
|
content_type_field='adherent_type',
|
|
|
object_id_field='adherent_id',
|
|
|
- related_query_name='corporations')
|
|
|
+ related_query_name='corporation')
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'personne morale'
|