From 20d863efc0826ddd930ff1f933b8de38324cc76a Mon Sep 17 00:00:00 2001 From: David Cain Date: Sun, 18 Jun 2023 10:18:11 -0600 Subject: [PATCH] Make discount URL field non-nullable This changes the field to be in line with Django recommendations: > Avoid using null on string-based fields such as `CharField` and > `TextField.` If a string-based field has `null=True`, that means it > has two possible values for "no data": `NULL`, and the empty string. > In most cases, it's redundant to have two possible values for "no > data;" the Django convention is to use the empty string, not `NULL`. https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.Field.null Three more fields on `Trip` have a large number of records with `null` -- I'd need to address those before I can turn on linting for DJ001. --- ws/migrations/0055_discount_url_non_null.py | 19 +++++++++++++++++++ ws/models.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ws/migrations/0055_discount_url_non_null.py diff --git a/ws/migrations/0055_discount_url_non_null.py b/ws/migrations/0055_discount_url_non_null.py new file mode 100644 index 00000000..e6665d7b --- /dev/null +++ b/ws/migrations/0055_discount_url_non_null.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.19 on 2023-06-18 16:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ws', '0054_allow_null_reminder_sent_at'), + ] + + operations = [ + migrations.AlterField( + model_name='discount', + name='url', + field=models.URLField(blank=True, default=''), + preserve_default=False, + ), + ] diff --git a/ws/models.py b/ws/models.py index df606ad5..49b92f66 100644 --- a/ws/models.py +++ b/ws/models.py @@ -129,7 +129,7 @@ class Discount(models.Model): name = models.CharField(max_length=255) summary = models.CharField(max_length=255) terms = models.TextField(max_length=4095) - url = models.URLField(null=True, blank=True) + url = models.URLField(blank=True) ga_key = models.CharField( max_length=63, # If blank, then we don't actually report this information to a spreadsheet