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

  • Home
  • SEARCH
  • 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 632173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:02:51+00:00 2026-05-13T20:02:51+00:00

How to filter objects with an author from a set of author s( User

  • 0

How to filter objects with an “author” from a set of “authors”(Users)?

The “objects” are Posts, having an author(ForeignKey to User).

I’m pretty much stumped by this, so I’d appreciate help with it. Of course one could go about this the naive way, by manually filtering them, but that would hit the database real hard. Thanks anyway.

EDIT:
Listing of Post:

class Post(models.Model):
    '''A Post or a Status Update.
    '''
    content=models.CharField(max_length=200)
    author=models.ForeignKey(django.contrib.auth.models.User, related_name="author")
    tags=models.ManyToManyField(Tag)
    replyTo=models.ManyToManyField(django.contrib.auth.models.User, related_name="replyTo")
    # Snip model methods

Clarification: I’m trying to filter based upon a set of users and not a single user (which is trivially easy to do)
when=models.DateTimeField(auto_now=True)

Thanks to everyone who helped with the previous question. Now I have one final thing to ask:

Code excerpt from UserProfile (connected to User):

def get_updates():
    return Post.objects.filter(author__in=(list(self.friends.all()) + [self]))

Is this the most efficient way to get all the posts by an author and its friends? (Note: This is a naive implementation, as it doesn’t handle pagination, etc. Will do that later)

  • 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-13T20:02:51+00:00Added an answer on May 13, 2026 at 8:02 pm

    Something like:

    Post.objects.filter(author=user)
    

    Where user is the relevant user should work, but it’s hard to give a good answer with no models

    EDIT

    Now that I understand your question, try this:

    Post.objects.filter(author__in=users)
    

    Where users is the set of users

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

Sidebar

Related Questions

I'm working on a system were a user can edit existing objects (Filter domain
I've got a object (Filter) that's defined something like this public class Filter {
I currently filter some message from my inbox with these steps: select inbox pick
I have a complex table pulled from a multi-ActiveRecord object array. This listing is
myqueryset = Content.objects.filter(random 100)
I've tried the following with no success: Match.objects.filter(sendDate__gte=dateToStats).values(sendDate__day).annotate(perDay=Count(id)).order_by() Fails with: Cannot resolve keyword 'sendDate__day'
idarr = [1,2,3,4,5] for i in range(len(idarr)): upload.objects.filter(idarr[i]) Cant we pass the idarr at
I have the following code, using Django ORM routes =Routes.objects.filter(scheduleid=schedule.id).only('externalid') t_list = [(route.externalid, route.vehicle.name)
I am trying to filter an IEnumerable object of the duplicate values, so I
I'm missing something here: $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry $objSearcher.Filter =

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.