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 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 have some codes like this: cats = Category.objects.filter(is_featured=True) for cat in cats: entries
I have a list of objects from a django queryset, e.g. my_list = MyObject.objects.filter(variable=something)
In django how to check whether any entry exists for a query sc=scorm.objects.filter(Header__id=qp.id) This
I'm having an issue with my linq query. I am trying to filter objects
This is my query count = Attend.objects.filter(date = NULL).count() This gives me an enter
From an example you can see a multiple OR query filter: Article.objects.filter(Q(pk=1) | Q(pk=2)
I have Dim objectsList as List(Of Object) = GetAllObjects() ' Filter from Objects just
class Content(models.Model): author = models.ForeignKey('auth.User') stamp = models.CharField(max_length=50) class Comments(models.Model): content = models.ForeignKey(Content) message
Not having much luck getting help from any of you Spring gurus on here.
Model.objects.filter(pk__in=[list of ids]) and Model.objects.filter(pk__in=[1,2,3]) How do I show this data in a template?

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.