Simplify family model and add Member.contact_email

- Replace the Guardianship through-model + self-referential M2M with a simple
  is_guardian flag on Member. Guardians in a family look after the family's
  dependents; guardians/dependents are now derived properties.
- Add Member.contact_email: own contact email, falling back to the linked
  user's login email, so a linked member need not store their email twice.
- Update admin (is_guardian in list/filter/inline; drop guardianship inline).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 00:18:35 +02:00
parent 2ead824c5d
commit aa2c6329b9
4 changed files with 70 additions and 101 deletions

View File

@@ -1,4 +1,4 @@
# Generated by Django 6.0.6 on 2026-07-01 22:04
# Generated by Django 6.0.6 on 2026-07-01 22:16
import accounts.managers
import django.db.models.deletion
@@ -29,13 +29,6 @@ class Migration(migrations.Migration):
'ordering': ['name'],
},
),
migrations.CreateModel(
name='Guardianship',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('relationship', models.CharField(choices=[('parent', 'Parent'), ('guardian', 'Guardian'), ('other', 'Other')], default='parent', max_length=20)),
],
),
migrations.CreateModel(
name='User',
fields=[
@@ -68,30 +61,12 @@ class Migration(migrations.Migration):
('emergency_phone', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, region=None)),
('license_number', models.CharField(blank=True, max_length=50)),
('date_of_birth', models.DateField()),
('is_guardian', models.BooleanField(default=False, help_text='Whether this member is a parent/guardian in their family.')),
('family', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='members', to='accounts.family')),
('guardians', models.ManyToManyField(related_name='dependents', through='accounts.Guardianship', through_fields=('child', 'guardian'), to='accounts.member')),
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='member', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['last_name', 'first_name'],
},
),
migrations.AddField(
model_name='guardianship',
name='child',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='child_links', to='accounts.member'),
),
migrations.AddField(
model_name='guardianship',
name='guardian',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='guardian_links', to='accounts.member'),
),
migrations.AddConstraint(
model_name='guardianship',
constraint=models.UniqueConstraint(fields=('guardian', 'child'), name='unique_guardianship'),
),
migrations.AddConstraint(
model_name='guardianship',
constraint=models.CheckConstraint(condition=models.Q(('guardian', models.F('child')), _negated=True), name='guardian_not_self'),
),
]