feat(people): Add first user data fields

To support choices in CharFields, Django choices enums have been
backported by bringing in the source file from Django 3.0.3

See #1
This commit is contained in:
James Graham
2020-02-21 17:10:26 +00:00
parent e4a50dbfa4
commit 6d2737b1a6
11 changed files with 194 additions and 5 deletions

View File

@@ -4,6 +4,9 @@ from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from backports.db.models.enums import TextChoices
class User(AbstractUser):
@@ -38,7 +41,36 @@ class Person(models.Model):
through='Relationship',
through_fields=('source', 'target'),
symmetrical=False)
###############################################################
# Data collected for analysis of community makeup and structure
class GenderChoices(TextChoices):
MALE = 'M', _('Male')
FEMALE = 'F', _('Female')
OTHER = 'O', _('Other')
PREFER_NOT_TO_SAY = 'N', _('Prefer not to say')
gender = models.CharField(max_length=1,
choices=GenderChoices.choices,
blank=True, null=False)
class AgeGroupChoices(TextChoices):
LTE_25 = '<=25', _('25 or under')
BETWEEN_26_30 = '26-30', _('26-30')
BETWEEN_31_35 = '31-35', _('31-35')
BETWEEN_36_40 = '36-40', _('36-40')
BETWEEN_41_45 = '41-45', _('41-45')
BETWEEN_46_50 = '46-50', _('46-50')
BETWEEN_51_55 = '51-55', _('51-55')
BETWEEN_56_60 = '56-60', _('56-60')
GTE_61 = '>=61', _('61 or older')
PREFER_NOT_TO_SAY = 'N', _('Prefer not to say')
age_group = models.CharField(max_length=5,
choices=AgeGroupChoices.choices,
blank=True, null=False)
@property
def relationships(self):
return self.relationships_as_source.all().union(