Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 274489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:37:06+00:00 2026-05-12T00:37:06+00:00

I want to display a menu that changes according to the user group of

  • 0

I want to display a menu that changes according to the user group of the currently logged in user, with this logic being inside of my view, and then set a variable to check in the template to determine which menu items to show….I’d asked this question before, but my logic was being done in the template. So now I want it in my view…The menu looks as below

   <ul class="sidemenu">
    <li><a href="/">General List </a></li>
    <li><a href="/sales_list">Sales List </a></li>
    <li><a href="/add_vehicle">Add a New Record </a></li>
    <li><a href="/edit_vehicle">Edit Existing Record </a></li>
    <li><a href="/filter">Filter Records </a></li>
    <li><a href="/logout">Logout </a></li>
  </ul>

Suppossing the user is management, they’ll see everything…But assuming the user is in the group sales, they’ll only see the first two and the last two items…and so on. I also want a dynamic redirect after login based on the user’s group. Any ideas?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:37:07+00:00Added an answer on May 12, 2026 at 12:37 am

    The standard Django way of checking permissions is by the individual permission flags rather than testing for the group name.

    If you must check group names, being aware that Users to Groups is a many-to-many relationship, you can get the first group in the list of groups in your template with something like this:

    {{ user.groups.all.0 }}
    

    or using it like this in a conditional (untested but should work):

    {% ifequal user.groups.all.0 'Sales' %}
       ...
    {% endif %}
    

    If you go with the preferred permission model you would do something like the following.

    ...
    
      {% if perms.vehicle.can_add_vehicle %}
        <li><a href="/add_vehicle">Add a New Record </a></li>
      {% endif %}
      {% if perms.vehicle.can_change_vehicle %}
        <li><a href="/edit_vehicle">Edit Existing Record </a></li>
      {% endif %}
    
    ...
    

    These are the permissions automatically created for you by syncdb assuming your app is called vehicle and the model is called Vehicle.

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

    If the user is in a Sales group they won’t have those vehicle permissions (unless you’ve added those to the group of course).

    If the user is in a Management group they can have those permissions, but you need to add them to the group in the Django admin site.

    For your other question, redirect on login based on user group: Users to Groups is a many-to-many relationship so it’s not really a good idea to use it like a one-to-many.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had datalist as menu that display categories and subs and I want to
I am building a menu that I want to display in a certain way.
I want to display a menu on every page that is run from a
I'm making a game and in the menu I want to display the text
I have a menu with button objects in As3. I want to display the
I did hidden eclipse main menu. I want to display all item of eclipse
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
In the header of the django admin, I want display a link. This link
I'm trying to build a front-end and back-end navigation menu. I want to display
I want to display a main menu on the left and a settings page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.