From 268f237d6ae3edadb5d00875d3c93f00568f1457 Mon Sep 17 00:00:00 2001 From: Martey Dodoo Date: Fri, 20 Jan 2017 01:04:28 -0500 Subject: [PATCH 1/2] Make some fields on Speaker model optional. This makes it easier to add/edit Speakers in the admin. - Make User relationship optional (since some Speakers will not have a User account associated with them if they are additional speakers to a proposal) by setting blank=True. - Make annotation field optional (similar to the field on the Sponsor model). - Make invite_email and invite_token fields optional by setting blank=True, since conventional Speakers attached to User accounts do not need these fields. This removes the uniqueness constraint from invite_token, but since null=True was set on that field (see https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.Field.null), it wasn't really unique anyway. --- .../migrations/0003_make_fields_optional.py | 43 +++++++++++++++++++ symposion/speakers/models.py | 8 ++-- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 symposion/speakers/migrations/0003_make_fields_optional.py diff --git a/symposion/speakers/migrations/0003_make_fields_optional.py b/symposion/speakers/migrations/0003_make_fields_optional.py new file mode 100644 index 00000000..a11d3128 --- /dev/null +++ b/symposion/speakers/migrations/0003_make_fields_optional.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2017-01-20 07:40 +from __future__ import unicode_literals + +import datetime +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('symposion_speakers', '0002_speaker_twitter_username'), + ] + + operations = [ + migrations.AlterField( + model_name='speaker', + name='annotation', + field=models.TextField(blank=True, verbose_name='Annotation'), + ), + migrations.AlterField( + model_name='speaker', + name='created', + field=models.DateTimeField(default=datetime.datetime.now, editable=False, verbose_name='Created'), + ), + migrations.AlterField( + model_name='speaker', + name='invite_email', + field=models.CharField(blank=True, db_index=True, default='', max_length=200, verbose_name='Invite_email'), + ), + migrations.AlterField( + model_name='speaker', + name='invite_token', + field=models.CharField(blank=True, db_index=True, max_length=40, verbose_name='Invite token'), + ), + migrations.AlterField( + model_name='speaker', + name='user', + field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='speaker_profile', to=settings.AUTH_USER_MODEL, verbose_name='User'), + ), + ] diff --git a/symposion/speakers/models.py b/symposion/speakers/models.py index 6e6de9d4..3b774aa7 100644 --- a/symposion/speakers/models.py +++ b/symposion/speakers/models.py @@ -20,7 +20,7 @@ class Speaker(models.Model): (2, "Two") ] - user = models.OneToOneField(User, null=True, related_name="speaker_profile", verbose_name=_("User")) + user = models.OneToOneField(User, blank=True, null=True, related_name="speaker_profile", verbose_name=_("User")) name = models.CharField(verbose_name=_("Name"), max_length=100, help_text=_("As you would like it to appear in the" " conference program.")) @@ -35,9 +35,9 @@ class Speaker(models.Model): blank=True, help_text=_(u"Your Twitter account") ) - annotation = models.TextField(verbose_name=_("Annotation")) # staff only - invite_email = models.CharField(max_length=200, unique=True, null=True, db_index=True, verbose_name=_("Invite_email")) - invite_token = models.CharField(max_length=40, db_index=True, verbose_name=_("Invite token")) + annotation = models.TextField(blank=True, verbose_name=_("Annotation")) # staff only + invite_email = models.CharField(blank=True, default="", max_length=200, db_index=True, verbose_name=_("Invite_email")) + invite_token = models.CharField(blank=True, max_length=40, db_index=True, verbose_name=_("Invite token")) created = models.DateTimeField( default=datetime.datetime.now, editable=False, From f7c365fe1efc65c0bb58e6fd3219899d1b0fed58 Mon Sep 17 00:00:00 2001 From: Martey Dodoo Date: Fri, 20 Jan 2017 03:39:11 -0500 Subject: [PATCH 2/2] Set speaker.invite_email to an empty string. CharFields should be set to empty strings, not None. --- symposion/speakers/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symposion/speakers/views.py b/symposion/speakers/views.py index f60064e0..809c806d 100644 --- a/symposion/speakers/views.py +++ b/symposion/speakers/views.py @@ -34,7 +34,7 @@ def speaker_create(request): speaker = form.save(commit=False) speaker.user = request.user if not found: - speaker.invite_email = None + speaker.invite_email = "" speaker.save() messages.success(request, _("Speaker profile created.")) return redirect("dashboard")