Extend admin, migrations, and tests for authentication and club apps
- Implement admin configurations for User, Member, Family, and FamilyMembership, with specialized inlines and filtered displays. - Introduce `UserCreationForm` and `UserChangeForm` for streamlined user management. - Enhance Family model with improved string representation and made name optional. - Add `Member.contact_email` property for prioritized email retrieval. - Include tests for the updated Family string logic, contact email functionality, and admin integration. - Add initial migration for club models (Club, ClubMembership) and updated migration for Family in the authentication app. - Configure IntelliJ IDEA for local SQLite database access.
This commit is contained in:
@@ -46,7 +46,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
|
||||
|
||||
class Family(UUIDModel):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("family")
|
||||
@@ -54,7 +54,12 @@ class Family(UUIDModel):
|
||||
ordering = ["name"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
if self.name:
|
||||
return self.name
|
||||
surnames = sorted({last_name for last_name in self.memberships.values_list("member__last_name", flat=True) if last_name})
|
||||
if surnames:
|
||||
return _("%(surnames)s family") % {"surnames": " / ".join(surnames)}
|
||||
return _("Family %(id)s") % {"id": str(self.pk)[:8]}
|
||||
|
||||
@property
|
||||
def guardians(self):
|
||||
@@ -98,6 +103,11 @@ class Member(UUIDModel):
|
||||
def get_short_name(self):
|
||||
return self.first_name
|
||||
|
||||
@property
|
||||
def contact_email(self):
|
||||
"""Best email to reach this member: own contact email, else login email."""
|
||||
return self.email or (self.user.email if self.user_id else "")
|
||||
|
||||
@property
|
||||
def guardians(self):
|
||||
return Member.objects.filter(
|
||||
|
||||
Reference in New Issue
Block a user