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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:19:00+00:00 2026-05-13T15:19:00+00:00

I have a model: class Zone(models.Model): name = models.CharField(max_length=128) users = models.ManyToManyField(User, related_name=’zones’, null=True,

  • 0

I have a model:

class Zone(models.Model):
    name = models.CharField(max_length=128)
    users = models.ManyToManyField(User, related_name='zones', null=True, blank=True)

And I need to contruct a filter along the lines of:

u = User.objects.filter(...zones contains a particular zone...)

It has to be a filter on User and it has to be a single filter parameter. The reason for this is that I am constructing a URL querystring to filter the admin user changelist: http://myserver/admin/auth/user/?zones=3

It seems like it should be simple but my brain isn’t cooperating!

  • 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-13T15:19:00+00:00Added an answer on May 13, 2026 at 3:19 pm

    Just restating what Tomasz said.

    There are many examples of FOO__in=... style filters in the many-to-many and many-to-one tests. Here is syntax for your specific problem:

    users_in_1zone = User.objects.filter(zones__id=<id1>)
    # same thing but using in
    users_in_1zone = User.objects.filter(zones__in=[<id1>])
    
    # filtering on a few zones, by id
    users_in_zones = User.objects.filter(zones__in=[<id1>, <id2>, <id3>])
    # and by zone object (object gets converted to pk under the covers)
    users_in_zones = User.objects.filter(zones__in=[zone1, zone2, zone3])
    

    The double underscore (__) syntax is used all over the place when working with querysets.

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

Sidebar

Related Questions

I have a model: class Customer(models.Model): name = models.CharField(max_length=200) email = models.EmailField() company =
I have a model: class Server(models.Model): serverId = models.IntegerField(verbose_name=_(serverId)) name = models.CharField(max_length=200, verbose_name=_(server_name)) ip
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have this model: class Category(models.Model): name = models.CharField() description = models.CharField(blank=True) parent =
I have this model: class option(models.Model): warval = models.ForeignKey(war) caption = models.CharField(max_length=20) text =
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
I'm newcomer in django, and here is question: I have model class: def Client(models.User)
I have django model: class UserProfile(models.Model): user = models.OneToOneField(User) #other fields When I create
I have a model class tournaments(models.Model): # .... total_rounds = models.IntegerField(max_length=11, blank=True, null=True) #

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.