The reason is because i want to add some user without entering their 
username. As i manage to allow null input for username but the unique for 
username make it an error if i add another user without username. These 
user are used for adding family member. For eg creating a 3 years old baby 
profile as family member.

On Wednesday, January 10, 2018 at 10:41:44 AM UTC+9, [email protected] 
wrote:
>
> Thanks for these improvement. But the main thing i want is to make 
> username field unique = false
>
> On Tuesday, January 9, 2018 at 5:39:32 PM UTC+9, [email protected] wrote:
>>
>> I am trying to make username unique = false as there are cases where 
>> username is not needed. Since i am using email address to login.
>> But with the django user model, how do i customise it ? 
>>
>> Here is the code for my current user model:
>>
>> from django.db import models
>> from django.contrib.auth.models import AbstractUser
>> from django.contrib.auth.models import UserManager
>> from django.db.models import Q
>> from django.core.validators import RegexValidator
>>
>>
>> class CustomUserManager(UserManager):
>>
>>     def get_by_natural_key(self, username):
>>         return self.get(
>>             # this comment is to prevent user from using username to login
>>             # Q(**{self.model.USERNAME_FIELD: username}) |
>>             Q(**{self.model.EMAIL_FIELD: username})
>>         )
>>
>>
>> class MyUser(AbstractUser):
>>     userId = models.AutoField(primary_key=True)
>>     gender = models.CharField(max_length=6, blank=True, null=True)
>>     nric = models.CharField(max_length=40, blank=True, null=True)
>>     birthday = models.DateField(blank=True, null=True)
>>     birthTime = models.TimeField(blank=True, null=True)
>>     ethnicGroup = models.CharField(max_length=30, blank=True, null=True)
>>     favoriteClinic = models.CharField(max_length=50, blank=True, null=True)
>>     appVer = models.CharField(max_length=50, blank=True, null=True)
>>     osVer = models.CharField(max_length=50, blank=True, null=True)
>>     mobileType = models.IntegerField(blank=True, null=True)
>>     country_code = models.IntegerField(blank=True, null=True)
>>     # mobile_regex = RegexValidator(regex=r'^(\+\d{1,3})?,?\s?\d{8,13}$', 
>> message="Phone number must not consist of space and requires country code. 
>> eg : +6591258565")
>>     mobileNo = models.CharField(max_length=25, blank=True, null=True)  # 
>> validators should be a list
>>     height = models.FloatField(blank=True, null=True)
>>     weight = models.FloatField(blank=True, null=True)
>>     bloodtype = models.CharField(max_length=3, blank=True, null=True)
>>     allergy = models.CharField(max_length=30, blank=True, null=True)
>>     # image1 = models.ImageField(upload_to=)
>>     # image = models.BinaryField(editable=True, blank=True, null=True)
>>     # displaypicture = models.ImageField
>>     objects = CustomUserManager()
>>
>>     def __str__(self):
>>         return self.username
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64c1269c-240b-4d65-8bab-0ee19a353b4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to