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 7759505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:38:49+00:00 2026-06-01T13:38:49+00:00

I have a basic permission system where I am pretty much hardcoding permissions based

  • 0

I have a basic permission system where I am pretty much hardcoding permissions based on user.profile.user_type, where user.profile is equivalent to user.get_profile().

For example, if a user_type is, say, 1 (property manager), then that user can view all work orders. A user_type of 2 (tenant) means that user can only view work orders that he created.

I am currently simply using a class-based generic view in urls.py like this

url(
    r'^orders/$',
    ListView.as_view(
        model = Order,
        template_name = 'doors/orders/list.html'
    ),
    name = 'orders_list'
),

and therefore I have no permissions control at all.

So to add a permissions system, should I control it in the template like this?

{% for order in order_list %}
    {% if request.user.profile.user_type == 1 %}
        # Show every order
        {{ order.pk }}
    {% else %}
        # Show only work orders created by that user
        {% if order.creator == request.user.pk %}
            {{ order.pk }}
        {% endif %}
    {% endif %}
{% endfor %}

I have a feeling that trying to filter inside the template is a waste of a lot of SQL hits, because no matter what the user_type is, the template will still force Django to call every work order. Is that true?

Or should I control it in the view like this?

def orders_list( request ) :
    if request.user.user_type == 1 :
        order_list = Order.objects.all()
    else :
        order_list = Order.objects.filter( creator = request.user.pk )

    dictionary = {
        'order_list' : order_list,
    }

    return render( request, 'doors/orders/list.html', dictionary )

Obviously if I try to control it inside views.py, then I can’t use the generic views anymore.

And lastly my third option would be to (somehow) control it inside the class-base generic view. I don’t even know if that’s even possible. Maybe somehow with get_context_data? I really like the simplicity of generic views, but I’m not too familiar with the more advanced OO concepts.

What are you guys’s suggestions?

  • 1 1 Answer
  • 0 Views
  • 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-06-01T13:38:50+00:00Added an answer on June 1, 2026 at 1:38 pm

    If you use ListView there is get_queryset() method to do this:

    class OrderListView(ListView):
        template_name = 'doors/orders/list.html'
    
        def get_queryset(self):
            user = self.request.user
            if user.user_type == 1:
                return Order.objects.all()
            return Order.objects.filter(creator=user.pk)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have basic hello word example of Prime Faces. I have created dynamic web
I have a basic PHP question, take the code below for example, let's say
We are developing a web app that will have a pretty complex user and
I'm trying to figure out a basic permission set for an IAM user/key to
I have a process with permissions 4750. Two users exist in my Linux system.
I have developed an app which requests permission from the user to access their
Sorry for the basic question - I'm a .NET developer and don't have much
I have basic idea on Kilo Virtual Machine on Mobiles , I have clear
I have a basic class that derived subclasses inherit from, it carries the basic
I have a basic question, in the Django template language how can you tell

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.