简体   繁体   中英

django system with signup and login features

I am trying to build a django system with signup and login features and I also want that the logged in user should be able to add notes to his profile. What approach should I take up for building my models?...creating a OneToOneField for User or creating a custom Django User model. Please help!

There are a few different ways to handle this. But it is probably easiest to to create a OneToOneField between User model and a profile model, for all the users details. This of course only makes sense if you are happy with the way django has structured its User Model.

If you are happy with the way django handled the auth, but just want to replace username with maybe email, and add some extra fields, then you can extend AbstractUser

If you don't like the way it handles auth you can maybe try and extend AbstractBaseUser.

Personally I would probably extend AbstractUser and use that. Your notes model can than have a ForeignKey to User.

Edit: I found this stackoverflow that gives a much more detailed answer Extending the User model with custom fields in Django .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM