Add unique constraint to Staff.username.

Previously had some duplicates for "pono" which were causing
MultipleObjectsReturned errors. A username is generally considered to be unique.
This commit is contained in:
Ben Sturmfels 2021-11-29 14:31:26 +11:00
parent 843b24c63a
commit 457e5739f7
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
4 changed files with 52 additions and 2 deletions

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2021-11-28 21:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Person',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=20)),
('formal_name', models.CharField(max_length=200)),
('casual_name', models.CharField(max_length=200)),
('currently_employed', models.BooleanField(default=True)),
('date_created', models.DateTimeField(auto_now_add=True)),
('date_last_modified', models.DateTimeField(auto_now=True)),
],
options={
'verbose_name_plural': 'people',
},
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2021-11-28 21:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('staff', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='person',
name='username',
field=models.CharField(max_length=20, unique=True),
),
]

View file

@ -7,7 +7,7 @@ class Person(models.Model):
Referenced from other models (blog, events, etc) Referenced from other models (blog, events, etc)
""" """
username = models.CharField(max_length=20) username = models.CharField(max_length=20, unique=True)
formal_name = models.CharField(max_length=200) formal_name = models.CharField(max_length=200)
casual_name = models.CharField(max_length=200) casual_name = models.CharField(max_length=200)
# title = models.CharField(max_length=200, blank=True) # title = models.CharField(max_length=200, blank=True)
@ -28,4 +28,3 @@ class Person(models.Model):
def biography_url(self): def biography_url(self):
return u"/about/#%s" % self.username return u"/about/#%s" % self.username