2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 17:17:08 +00:00

Model change: add 1:1 link Person:User

This commit is contained in:
2025-01-21 19:18:17 +00:00
parent a784ca8641
commit c5357cab3d
2 changed files with 13 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ getcontext().prec = 2 # use 2 significant figures for decimal calculations
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.models import User
import settings import settings
@@ -82,8 +83,10 @@ class Person(TroggleModel):
first_name = models.CharField(max_length=100) first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100)
fullname = models.CharField(max_length=200) # display name, but should not be used for lookups fullname = models.CharField(max_length=200) # display name, but should not be used for lookups
nickname = models.CharField(max_length=200) nickname = models.CharField(max_length=200, blank=True)
slug = models.SlugField(max_length=50, blank=True, null=True) # unique, enforced in code not in db slug = models.SlugField(max_length=50, blank=True, null=True) # unique, enforced in code not in db
# no delete cascade. We have users without Persons, and Persons without users
user = models.OneToOneField(User, models.SET_NULL, blank=True, null=True)
is_vfho = models.BooleanField( is_vfho = models.BooleanField(
help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.",
@@ -92,7 +95,7 @@ class Person(TroggleModel):
is_guest = models.BooleanField(default=False) # This is per-Person, not per-PersonExpedition is_guest = models.BooleanField(default=False) # This is per-Person, not per-PersonExpedition
mug_shot = models.CharField(max_length=100, blank=True, null=True) mug_shot = models.CharField(max_length=100, blank=True, null=True)
blurb = models.TextField(blank=True, null=True) blurb = models.TextField(blank=True, null=True)
orderref = models.CharField(max_length=200) # for alphabetic orderref = models.CharField(max_length=200, blank=True) # for alphabetic
def get_absolute_url(self): def get_absolute_url(self):
# we do not use URL_ROOT any more. # we do not use URL_ROOT any more.

View File

@@ -8,7 +8,7 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from troggle.core.models.troggle import DataIssue from troggle.core.models.troggle import DataIssue, Person
"""This imports the registered troggle users, who are nearly-all, but not quite, Persons. """This imports the registered troggle users, who are nearly-all, but not quite, Persons.
exceptions are "expo" and "expoadmin" which are created by the databaseReset.py import program. exceptions are "expo" and "expoadmin" which are created by the databaseReset.py import program.
@@ -46,6 +46,12 @@ def register_user(u, email, password=None, pwhash=None):
except Exception as e: except Exception as e:
print(f"Exception <{e}>\n{len(User.objects.all())} users now in db:\n{User.objects.all()}") print(f"Exception <{e}>\n{len(User.objects.all())} users now in db:\n{User.objects.all()}")
raise raise
expoers = Person.objects.filter(slug=u)
if len(expoers) == 1:
person = expoers[0]
person.user = user
person.save()
return user return user
def get_encryptor(): def get_encryptor():