3
The django model fields are default to be NOT NULL
And if you want it allow NULL
values, use null=True
parameter.
If you want it allow empty value (” but not null), use blank=True
parameter.
And if you want that field to be unique, set unique=True
class UserRegister(models.Model):
first_name = models.CharField(max_length=150, null=True, blank=True)
last_name = models.CharField(max_length=150, null=True, blank=True)
email = models.EmailField(unique=True)
Maybe I misunderstood you question, you want to modify the User model fields.
And because you just can’t update the User model declaration, if you want to do so, you have the following choices:
- Make other fields to hold it, outside the
user
field. - Inherits the model from
User
, not use combination, then override the field.
Hope it helps.
1
If you need to change what attributes are required or if you need other data about a user, I would suggest writing your own user model instead another model that links to Django’s. Docs are here, it’s not too difficult: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
- [Django]-Do I need CSRF-protection without users or login?
- [Django]-Django: m2m_changed not fired when end of relation is deleted
- [Django]-Can I add more than two arguments to get_context_data()?
- [Django]-Firing notifications at specific times in Django