Complete people-domain move into members app; keep names on Member

Finish relocating Member/Family/FamilyMembership from authentication into
a dedicated members app, and revert the half-applied move of member names
onto the global User.

- members: add first_name/last_name back to Member (the whole codebase —
  tests, CSV importer, club app, admin — assumes them, and login-less
  children in families need a name); restore local ordering/index and the
  member__last_name lookups in Family.__str__ and FamilyMembership.
- authentication: drop first_name/last_name from User; get_full_name/
  get_short_name delegate to the linked member, else fall back to email.
- migrations: create members.0001_initial, repoint club.ClubMembership FK
  (club.0005), delete the models from authentication (0004, rewritten to
  plain DeleteModel ops in child-first order to avoid a SQLite table-remake
  crash).
- fix stale imports across apps (authentication/club tests, CSV importer)
  and missing imports/URLs in members tests; add missing _ import in
  members/admin.py; export MemberCsvImporter from members.services.

Full suite green (64 tests), ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-12 00:16:41 +02:00
parent 19b92d61f7
commit f3b1ae7e82
29 changed files with 942 additions and 664 deletions

62
members/admin.py Normal file
View File

@@ -0,0 +1,62 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import Family, FamilyMembership, Member
# Register your models here.
class MemberFamilyInline(admin.TabularInline):
"""Family memberships shown on the Member page."""
model = FamilyMembership
extra = 1
autocomplete_fields = ("family",)
@admin.register(Member)
class MemberAdmin(admin.ModelAdmin):
list_display = ("last_name", "first_name", "contact_email", "phone_display", "emergency_phone_display", "user")
list_select_related = ("user",)
search_fields = ("first_name", "last_name", "email")
autocomplete_fields = ("user",)
inlines = [MemberFamilyInline]
fields = ("user", "first_name", "last_name", "date_of_birth", "email", "phone", "emergency_phone")
@admin.display(description=_("email"), ordering="email")
def contact_email(self, obj):
return obj.contact_email
@admin.display(description=_("phone"), ordering="phone")
def phone_display(self, obj):
return obj.phone.as_international if obj.phone else ""
@admin.display(description=_("emergency phone"), ordering="emergency_phone")
def emergency_phone_display(self, obj):
return obj.emergency_phone.as_international if obj.emergency_phone else ""
class FamilyMemberInline(admin.TabularInline):
"""Members shown on the Family page."""
model = FamilyMembership
extra = 1
autocomplete_fields = ("member",)
@admin.register(Family)
class FamilyAdmin(admin.ModelAdmin):
list_display = ("__str__", "member_count")
search_fields = ("name", "memberships__member__first_name", "memberships__member__last_name")
inlines = [FamilyMemberInline]
@admin.display(description=_("members"))
def member_count(self, obj):
return obj.memberships.count()
@admin.register(FamilyMembership)
class FamilyMembershipAdmin(admin.ModelAdmin):
list_display = ("family", "member", "role")
list_filter = ("role",)
autocomplete_fields = ("family", "member")
search_fields = ("family__name", "member__first_name", "member__last_name")