SoFunction
Updated on 2024-10-30

Django use Profile to extend the User module way

First create the Profile application

python startapp profiles

profiles/

# -*- coding: utf-8 -*-
from  import models
from  import User
from  import post_save

class UserProfile():
  user = (User)
  nickname = (max_length=16, default='', blank=True)
  sex = (default=0)
  phone = (max_length=16, default='', blank=True)

  def __str__(self):
    return 

  def __unicode__(self):
    return 

def create_user_profile(sender, instance, created, **kwargs):
  if created:
    profile = UserProfile()
     = instance
    ()

post_save.connect(create_user_profile, sender=User)

profiles/

# -*- coding: utf-8 -*-
from  import admin
from  import User
from  import UserAdmin
from .models import UserProfile

class ProfileInline():
  model = UserProfile
  max_num = 1
  can_delete = False

class UserProfileAdmin(UserAdmin):
  inlines = [ProfileInline, ]

(User)
(User, UserProfileAdmin)

increase

AUTH_PROFILE_MODULE = ''

beta (software)

$ python  syncdb
$ python  shell
>>> from  import User
>>> user = User()
>>> ='testuser'
>>> ()
>>> ()[0].userprofile

Additional knowledge:Solution for login to accounts/profile/ in django

Add a line to the project's setting and Okay!

LOGIN_REDIRECT_URL = '/index'

Above this Django using Profile to extend the User module way is all I have shared with you, I hope to give you a reference, and I hope you support me more.