in Education by
I have a Django application which allows different kinds of users: firms, administrators, external people etc. Of course all of this is easy to manage with the default authentication system and groups. My problem is that users belonging to different groups will have different related information - for instance firms will need to provide some commercial information that does not make sense for private users. Hence I need to attach different kind of profiles, depending on the group. (In my application groups are mutually exclusive.) Unfortunately, Django only allows a single model to be attached as a profile, and that model is declared in settings.AUTH_PROFILE_MODULE. Internally, that is retrieved by the User.get_profile() method, which basically just reads this value and performs some checks, for instance that the model actually exists. I was thinking of subclassing User and overriding the get_profile() method, so that it returns a different model depending on the group. Is there a simpler/cleaner way to manage different kind of profiles? What I am proposing seems a little hack, considering that user profiles were introduced exactly to avoid having to subclass User. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Create a model with OneToOneField to User and related_name. E. g.: class Firm(models.Model): user = models.OneToOneField(User, related_name='firm') # other fields class External(models.Model): user = models.OneToOneField(User, related_name='external') # other fields Then you can check the existance of this attributes in user (if hasattr(request.user, 'firm')) and return proper instance. I'd put it in custom middleware, which would set request.user_profile for example.

Related questions

0 votes
    What are the different types of profiles in Informatica?...
asked Mar 27, 2021 in Technology by JackTerrance
0 votes
    Can two users have the same profile? Can two profiles be assigned to the same user in Salesforce?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    what are different types of user defined functions in c++ Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    What is user authentication in Django?...
asked Jul 1, 2021 in Technology by JackTerrance
0 votes
    How profiles are specified in Maven?...
asked May 4, 2021 in Technology by Editorial Staff
0 votes
    Some one answer please what are user defined data types ? Select the correct answer from above options...
asked Dec 7, 2021 in Education by JackTerrance
0 votes
    Some one answer please what are user defined data types ? Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    Some one answer please what are user defined data types ? Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    What is User-defined function? What are its various types?...
asked Dec 11, 2020 in Technology by JackTerrance
0 votes
    _____________ is a malicious method used by cyber-criminals to trick a user into clicking on something different from what ... questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 3, 2021 in Education by JackTerrance
0 votes
    How are user stories, epics, and tasks different?...
asked Nov 19, 2020 in Technology by Editorial Staff
0 votes
    What are the different types of Blockchain?...
asked Jan 22, 2023 in Technology by JackTerrance
0 votes
    What are different types of sensors in IoT?...
asked Jan 18, 2023 in Technology by JackTerrance
0 votes
    What are the different types of AI?...
asked Jan 17, 2023 in Technology by JackTerrance
0 votes
    A __________ is an R-object which can contain many different types of elements inside it. (a) Vector (b) ... Out of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
...