From 74f213e1d59e3dacc62d97610f19af6c43fa4f00 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 02:37:03 +0100 Subject: [PATCH] Set default value for validation_slug --- .../migrations/0007_auto_20180213_0128.py | 21 +++++++++++++++++++ membership/models.py | 12 +++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 membership/migrations/0007_auto_20180213_0128.py diff --git a/membership/migrations/0007_auto_20180213_0128.py b/membership/migrations/0007_auto_20180213_0128.py new file mode 100644 index 00000000..0dd7b54a --- /dev/null +++ b/membership/migrations/0007_auto_20180213_0128.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-02-13 01:28 +from __future__ import unicode_literals + +from django.db import migrations, models +import membership.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('membership', '0006_auto_20160526_0445'), + ] + + operations = [ + migrations.AlterField( + model_name='customuser', + name='validation_slug', + field=models.CharField(db_index=True, default=membership.models.get_validation_slug, max_length=50, unique=True), + ), + ] diff --git a/membership/models.py b/membership/models.py index 73804008..559b0276 100644 --- a/membership/models.py +++ b/membership/models.py @@ -59,6 +59,10 @@ class MyUserManager(BaseUserManager): return user +def get_validation_slug(): + return make_password(None) + + class CustomUser(AbstractBaseUser, PermissionsMixin): VALIDATED_CHOICES = ((0, 'Not validated'), (1, 'Validated')) site = models.ForeignKey(Site, default=1) @@ -66,8 +70,12 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(unique=True) validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) - validation_slug = models.CharField(db_index=True, unique=True, - max_length=50) + # By default, we initialize the validation_slug with appropriate value + # This is required for User(page) admin + validation_slug = models.CharField( + db_index=True, unique=True, max_length=50, + default=get_validation_slug + ) is_admin = models.BooleanField( _('staff status'), default=False,