Multiple levels of user in django application

158 views
Skip to first unread message

Anju SB

unread,
Nov 28, 2014, 6:16:41 AM11/28/14
to django...@googlegroups.com
Dear Friends,

I want to develop a django based GIS web application.  In my application there are different levels of users namely station level user, circle level user etc.  Each user details are provided in different table,  How can I map/ relate the user with these tables.  Pleas help me to solve this issue.  

Thanks & Regards,
   
   Anju

Scot Hacker

unread,
Nov 28, 2014, 12:54:34 PM11/28/14
to django...@googlegroups.com

On Friday, November 28, 2014 3:16:41 AM UTC-8, Anju SB wrote:
Dear Friends,

I want to develop a django based GIS web application.  In my application there are different levels of users namely station level user, circle level user etc.  Each user details are provided in different table,  How can I map/ relate the user with these tables.  Pleas help me to solve this issue.  

I think of situations like this as having two prongs:

1) Various groups have various permission levels in portions of the project
2) Group members may have additional data/fields associated with their profiles.

For #1, use Django's Groups system to assign group memberships and  permissions as needed. You can start using those permissions throughout your project immediately.

For #2, you can create additional profile sub-types, keyed to a base profile. e.g. maybe everyone gets a UserProfile, while instructors also get an InstructorProfile that's FK'd to UserProfile. You can use post-save signals or other mechanisms to make sure that everyone has the right additional profile fields. Now let's say a user is looking at their profile editor - you could say "If user in group Instructors, also let them edit their associated InstructorProfile."

There are many ways to skin this cat...

./s

Anju SB

unread,
Nov 29, 2014, 12:51:00 AM11/29/14
to django...@googlegroups.com
Thank you Scot Hacker.   
     But my application needs more than one user from the same group. 

Timothy W. Cook

unread,
Nov 29, 2014, 3:04:49 AM11/29/14
to django...@googlegroups.com
On Sat, Nov 29, 2014 at 3:51 AM, Anju SB <anju...@gmail.com> wrote:
Thank you Scot Hacker.   
     But my application needs more than one user from the same group. 


​You can have multiple users in a group. That is kind of the definition of a group.  :-)


HTH,
Tim




 

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5750f591-276b-49da-bfc5-61c4d0a51f07%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

============================================
Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Anju SB

unread,
Nov 29, 2014, 3:49:40 AM11/29/14
to django...@googlegroups.com
Actually my application needs to store different information about  each group of users and needs to map these data with the auth_user table. 

Timothy W. Cook

unread,
Nov 29, 2014, 6:19:35 AM11/29/14
to django...@googlegroups.com
On Sat, Nov 29, 2014 at 6:49 AM, Anju SB <anju...@gmail.com> wrote:
Actually my application needs to store different information about  each group of users and needs to map these data with the auth_user table. 


​Yes.  You can create a model for that information and then use the group as a key.  ​
​There are similar examples you​ find with a search engine.  The mailing list and stackoverflow are good places to look. 



 

For more options, visit https://groups.google.com/d/optout.

Anju SB

unread,
Nov 29, 2014, 6:33:18 AM11/29/14
to django...@googlegroups.com
But the user's details are in different models , Groups may have different fields....

Timothy W. Cook

unread,
Nov 29, 2014, 7:42:09 AM11/29/14
to django...@googlegroups.com
You may need to re-think your model design or add a model that aggregates the others and use it to link to the group model?  There are many options but only you know the best one. 


For more options, visit https://groups.google.com/d/optout.

Anju SB

unread,
Nov 29, 2014, 11:49:25 AM11/29/14
to django...@googlegroups.com

Thank your for your reply.  Actually I created another model that aggregates all the values from each group table.  but after analyzing I feel its a worst method and performance is also very low.So model re-design is the only way to sort out this issue and need  help for redesigning the models.  Because I want to add users and map these users to group details from the admin page.  I am very confused state and I don't know how to re-design and optimize the queries.   

Scot Hacker

unread,
Nov 29, 2014, 12:20:25 PM11/29/14
to django...@googlegroups.com
On Saturday, November 29, 2014 8:49:25 AM UTC-8, Anju SB wrote:

Thank your for your reply.  Actually I created another model that aggregates all the values from each group table.  but after analyzing I feel its a worst method and performance is also very low.So model re-design is the only way to sort out this issue and need  help for redesigning the models.  Because I want to add users and map these users to group details from the admin page.  I am very confused state and I don't know how to re-design and optimize the queries.   

 
Django makes it easy to have multiple profile types with different sets of custom fields, and various permissions levels (roles). The admin does a good job of letting you add users to groups. I think you're going to have to spell out your problem/goals with more detail - we're not clear on exactly what's not working for you.  It might help (you and us) if you sketched out your desired model relationships with a charting tool or graphics program, or even as ascii art. 

./s

Cal Leeming

unread,
Nov 29, 2014, 12:30:11 PM11/29/14
to django...@googlegroups.com
I'm not sure if this was one of your requirements, but as you raised the concern of performance I thought it was worth mentioning.

Object level permissions in Django will create an additional row for every object you set a permission on, this can have a devastating impact on performance depending on how many users/objects you are storing. You can implement inherited permissions (e.g. explicitly define a parent model for each child) and have it traverse up the tree until it finds a relevant permission. So this allows you to make bulk changes without having to write a row for every related object, E.g. 1mil children belonging to a single parent object, you set the permissions on parent object, perm changes then only have to be applied once, rather than 1mil repeated. If this is something you need, let me know and I'll rip out the code we did for it (I haven't done a clean OSS release for it yet, so YMMV). It has zero admin panel support.

Scot replied just as I was writing this, and I second his request for some sort of sketch up of what you are asking for, as I'm not quite sure I understand your original question

Cal

Message has been deleted

Anju SB

unread,
Dec 2, 2014, 12:00:51 AM12/2/14
to django...@googlegroups.com, c...@iops.io
Actually I can't change the models of the different user details (state_data,district_data,dub-division_data,circle_data,station_data) because these tables are used for other GIS activities.  
I need to map user with these tables.

James Schneider

unread,
Dec 2, 2014, 12:20:59 AM12/2/14
to django...@googlegroups.com, c...@iops.io

Scot Hacker

unread,
Dec 2, 2014, 1:55:48 AM12/2/14
to django...@googlegroups.com, c...@iops.io


On Monday, December 1, 2014 9:00:51 PM UTC-8, Anju SB wrote:
Actually I can't change the models of the different user details (state_data,district_data,dub-division_data,circle_data,station_data) because these tables are used for other GIS activities.  
I need to map user with these tables.


Looks like you deleted the message that contained the schema for the other tables, but I would probably give each of them a ForeignKey connection to your UserProfile model. Then you can do something like 

profile = UserProfile.objects.get(user__username='joe')

if profile.StateData:
    ....

It's hard to say more without being closer to the code or having a better sense of your goals.

./s 

Anju SB

unread,
Dec 2, 2014, 4:53:36 AM12/2/14
to django...@googlegroups.com, c...@iops.io


We can't modify the 5 user details tables, because the other applications are associated with that table. It is required to map these table with user table.  But using the foreign key relationship we can only relate to one table. How can I design models without affecting the 5 tables mentioned.  

Scot Hacker

unread,
Dec 2, 2014, 11:49:51 AM12/2/14
to django...@googlegroups.com, c...@iops.io


On Tuesday, December 2, 2014 1:53:36 AM UTC-8, Anju SB wrote:


We can't modify the 5 user details tables, because the other applications are associated with that table. It is required to map these table with user table.  But using the foreign key relationship we can only relate to one table. How can I design models without affecting the 5 tables mentioned.  


 FK the UserProfile to those tables, not the other way around. That will leave them untouched/unmodified.

./s


Reply all
Reply to author
Forward
0 new messages