Django multi-user inputs - best approach?

I am currently developing a Django site in which users can have multiple “accounts” so that they can easily switch between different public profiles when interacting through the site. The fact that I am developing is likely to attract several registrations per person (and will not be discouraged), I just would like to offer this in such a way that users can associate profiles, easily switch and only register at a time.

Two approaches that I have come up with so far include:

  • One model ( User model + SiteProfile ) and many PublicProfile models per person. AUTH_PROFILE_MODULE set to the SiteProfile model. The problem is that I cannot easily use permissions for each object: they will be set in the User object, and not in the public profile, so pageview permissions for "PublicProfileA" will also be applied when the user masquerades as "PublicProfileB".

  • One Account model and many ( User model + UserProfile model) pairs per person. AUTH_PROFILE_MODULE set to the UserProfile model. This will have the added benefit of permissions that work as intended, and that I can simply create a user backend that will switch users by authenticating the user if they are currently logged in as another user that has the same Account object as External key. Authentication occurred by reading the fields in the Account object, although this would mean that the password field for each User object would be wasted.

  • As stated above, but subclassing Account from User . I was strongly opposed to this, though (for unknown reasons).

Are there any pitfalls or better approaches to this? Ultimately, you should use the built-in User model as a one-on-one model that identifies a group of open profiles (of which these profiles have FK back to the User object) or use it as the profile itself associated with a single Account object for each person ?

+6
source share
1 answer

Yes, I think the best approach would be to have one and only one user per person and several PublicProfile objects that they can “switch” between them. This gives an advantage to only one username / password for them and seems to make the most sense in how Django auth normally works.

0
source

Source: https://habr.com/ru/post/915187/


All Articles