This is a fairly common need in academia, where your users need a different set of profile fields depending on affiliation. And you always end up with edge cases where some people are simultaneously faculty and staff, or even student and faculty, etc. And those "special" people will need to have all of the right fields available to them. You could take an approach something like this:
- Set up standard Groups for Students, Faculty, Staff (and maybe Alumni) - Have a management command or import script that ensures everyone is in all the right groups - Set up a shared UserProfile model that includes all shared fields - For convenience, set up model methods on UserProfile that determine a person's status based on group membership, e.g. `is_faculty()`, `is_student()` etc. (taking care to not interfere with Django' built-in `is_staff` boolean!). This way you can do quick affiliation checks from anywhere (e.g. in templates) - Set up additional FacultyProfile, StudentProfile, StaffProfile classes with the unique fields and with ForeignKeys to UserProfile - Either in your import scripts or in save() method or elsewhere, instantiate the additional profile classes: if user.is_faculty(): fac_profile = FacultyProfile.objects.get_or_create(user=self) That's very loose and there are many ways to go about it, but that's one possible approach. Another would be to simply put *all* possible fields on UserProfile and just populate them based on affiliation. That's not very clean though, because if someone stops being faculty for instance, it would be tricky to ensure you remove all of the right field data (it's messy). So season to taste. ./s On Saturday, May 13, 2017 at 7:32:27 AM UTC-7, Ajat Prabha wrote: > > Hello everyone, > I'm creating a payment gateway to make transactions on my college campus > go cashless. It can be used to pay library dues, stationary charges, etc. > The user will add money to a central account and then he/she can use that > money virtually. I chose Django because of its security. But as I need 3 > groups of users viz. Faculty, Student and Staff, I'm having trouble to > implement this in the best possible way. I fix one thing, the other gets > disturbed. I'm new to Django, so I don't have much experience. I'm > comfortable with views, basic models, etc. But this User customization, I > can't get it right. > > I'm attaching a representational User model (any suggestions are welcome), > please have a look. All the 3 groups will have certain fields common and > certain fields specific to that group only like roll_number/employee_code > and permission_sets(in case the system is later used for access to labs, > etc.). The fields at below of the image will be common to all groups. > > > <https://lh3.googleusercontent.com/-ApmIsfCMgnY/WRcInaw2xrI/AAAAAAAAA94/sLaL-TCzPswVdAb_zKgRtnwEj8KEa4yeACLcB/s1600/IMG_20170513_175313.jpg> > > I also tried this > <https://drive.google.com/open?id=0Bz8W8OncbJROWHZLUXhsTmdETlU> customization > which > worked but then I had issues in Django admin view where the password was > stored in plain hashed value. I think it has something to do with > reimplementing ReadOnlyPasswordHashWidget method declared in > django.contrib.auth.forms but I'm not sure! > > I chose Django in the first place for security reasons and I'm not able to > get it right. > Can someone please help me out. > > Thanks! > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0c767ab1-5742-4441-8e57-fdb828325f68%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.