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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:17:55+00:00 2026-06-01T18:17:55+00:00

suppose the following simple models: class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() class

  • 0

suppose the following simple models:

class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

class Entry(models.Model):
    blog = models.ForeignKey(Blog)
    headline = models.CharField(max_length=255)
    body_text = models.TextField()
    author = models.ForeignKey(User, related_name='author_set')

How can I get all the authors that participated in a particular blog (i.e. pk=1)? I tried something like this, but it didn’t work.

User.objects.author_set.filter(blog=Blog.objects.get(pk=1))

Many thanks in advance!

  • 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-01T18:17:56+00:00Added an answer on June 1, 2026 at 6:17 pm
    User.objects.filter(author_set__blog__pk=1)
    

    I wasn’t paying attention to your related name, so the code above (revised) now uses the proper related name. However, this is a really bad related name. The related name should describe what’s on the opposite side, i.e. Entry. So really it should be related_name='entry_set'. However, that’s the default anyways, so you can remove related_name if you just want that. I would typically use a simple pluralized version of the related class, which would be in this case related_name='entries'. Or, you might want to use something like “blog_entries” to be more specific.

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

Sidebar

Related Questions

Suppose I have the following (trivially simple) base class: public class Simple { public
In a Django UserProfile model, I am trying to do the following: class UserProfile(models.Model):
Suppose we have a simple database containing following data: name apple pear banana grape
Suppose you are given a Class.dll assembly compiled from the following simple code: namespace
I have the following model : class A: b = ForeignKey('B') class B: a
Lets suppose that I have the following simple query var q = from p
Suppose the following object structure: class Super {} class SubA extends Super {} class
Suppose the following class public class Message { // some code } And a
Suppose the following XAML defined window: <Window x:Class=LayoutTests.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:LayoutTests Title=Window1> <Window.Resources> <XmlDataProvider
Suppose I have following code package memoryleak; public class MemoryLeak { public static int

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.