Extending the User model with custom fields in Django

后端 未结 13 1406
别那么骄傲
别那么骄傲 2020-11-21 23:28

What\'s the best way to extend the User model (bundled with Django\'s authentication app) with custom fields? I would also possibly like to use the email as the username (fo

相关标签:
13条回答
  • 2020-11-22 00:26

    Extending Django User Model (UserProfile) like a Pro

    I've found this very useful: link

    An extract:

    from django.contrib.auth.models import User

    class Employee(models.Model):
        user = models.OneToOneField(User)
        department = models.CharField(max_length=100)
    
    >>> u = User.objects.get(username='fsmith')
    >>> freds_department = u.employee.department
    
    0 讨论(0)
提交回复
热议问题