django - Get user group in a template -


I want to display a menu that changes according to the currently logged in user's user group, which is contained in this argument. My view, and then to check in the templates, set a variable to show which menu item .... I had asked this question before, but my argument was being done in the template. So now I want it in my view ... menu will look below

   

Supporting the user is management, they will all see ... but considering the user in the sale of the group, they will only see the first two and the last two items .. and similarly. I also want a dynamic redirect after login based on the user's group. Any ideas?

Check the permissions for the standard design of the default way the demo group name is group name.

If you want to check group names, then know that for the group users have multiple relationships, you can get the group first in the list of groups In your template with something like this:

  {{user.groups.all.0}}  

or use this method in a conditional way (Untested but should work):

  {% ifequal user.groups.all.0 'sale'%} ... {% endif%}  
< P> If you go with a favorite permission model then you do something like Are.

  ... {% perms.vehicle.can_add_vehicle%} 
  • gt; & Lt; A href = "/ add_vehicle" & gt; Add a new record & lt; / A & gt; & Lt; / Li & gt; {% Endif%} {% perms.vehicle.can_change_vehicle%} and
  • gt; & Lt; A href = "/ edit_vehicle" & gt; Edit existing record & lt; / A & gt; & Lt; / Li & gt; {% Endif%} ...
  • This is automatically generated by syncdb to handle your code called vehicle There are permissions made by and the model is called vehicle .

    If the user is a superuser then they have all the permissions.

    If users are in the Sales Group, then they 'permit those vehicles (unless you definitely do not add to the group).

    If the user is in the management group, those permissions can be, but you have to add them to the group For your other questions, redirect to the user group based on login: There are many relationships, so this is not really a good idea as it is one-to-many.


    Comments

    Popular posts from this blog

    c++ - Linux and clipboard -

    What is expire header and how to achive them in ASP.NET and PHP? -

    sql server - How can I determine which of my SQL 2005 statistics are unused? -