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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:55:21+00:00 2026-05-19T01:55:21+00:00

I have some middleware which takes a tuple (of usernames… it only allows usernames

  • 0

I have some middleware which takes a tuple (of usernames… it only allows usernames in the tuple to pass through certain areas of the site).

I have a UserProfile model which contains information about each user, and I want to filter it so that it returns a tuple of usernames for use with this middleware — in otherwords, set a variable BETA_USERS = (dynamically-generated-tuple).

Have you got any suggestions for accomplishing this?

Edit:

So, the tuple really isn’t an important detail — here’s an example:

Generally, I would just hard-code this into settings:

BETA_USERS = ('username1', 'username2', 'username3', 'username4')

However, I have a UserProfile model which contains a Beta column, which can be set to 1. The first 50 people to sign up for the beta will be set to 1, everyone else 0. So, I can easily filter this by calling a filter method on a model object:

users = UserProfile.objects.filter(beta='1')

and I can make that a nice tuple with this strange little loop:

for user in users:
    list.append((user.user.username).upper())
return tuple(list)

I guess my real question is, what is the best way for me to call this in my settings file?

or, stated another way, what’s the best way to assign dynamically created variables in the settings file?

  • 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-05-19T01:55:21+00:00Added an answer on May 19, 2026 at 1:55 am

    You can also use the @user_passes_test decorator to restrict views to particular subsets of users. Or create your own decorator:

    from django.utils.functional import wraps
    
    def beta(view):
        @wraps(view)
        def inner(request, *args, **kwargs):
            if request.user.user_profile.beta:
                return view(request, *args, **kwargs)
            # Up to you how you return failure...
        return inner
    

    Now you can use it as:

    @beta
    def my_view(request):
        # do something new here.
    

    The alternative is:

    @user_passes_test(lambda u: u.profile.beta)
    def my_view(request):
        # do something clever
    

    The advantage of the @beta form is that it is a bit easier to re-use.

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

Sidebar

Related Questions

OK, I'm actually calling some java middleware that returns a captcha image. The captcha
I have some things I need to use custom SQL for. Just to start,
I have modified the multihost.py middleware I found at http://effbot.org/zone/django-multihost.htm to set the settings.SITE_ID
so I have been playing around with django for a bit and I really
I'm looking for existing middleware solutions that address aspects of service clustering/distribution for load-balancing
Can you please provide me with some tips/guidelines when architecting, designing and implementing a
I am working on a project which contains two servers, one is written in
I would like to set a specific cookie domain for my cookies, because this
I'm new to Ruby on Rails (formerly and currently PHP expert) so forgive my

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.