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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:42:59+00:00 2026-06-10T01:42:59+00:00

I am still getting the hang of Django. For example, you have two models

  • 0

I am still getting the hang of Django. For example, you have two models and one of them is related to the other using ForeignKey.

class Parent(models.Model):
   name = models.CharField(max_length=255)
   birthday= models.DateField(blank=True,null=True)

class Child(models.Model):
   name = models.CharField(max_length=255)
   parent= models.ForeignKey(Parent)

In the example above, i would like to access the particular child and get his name. I will like to do it through the parent instance. So for example, i have a Parent called John and i would like to know his child’s name. How do i do it?

Please pardon me if it is a simple question…

  • 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-10T01:43:01+00:00Added an answer on June 10, 2026 at 1:43 am

    The below code addresses your question. Note that child_set is the related manager’s default name. For more information, see https://docs.djangoproject.com/en/dev/ref/models/relations/

    john = Parent.objects.get(name='John')
    johns_children = john.child_set.all()
    # Print names of his children
    for child in johns_children:
        print child.name
    # Get child named Jack
    jack = john.child_set.get(name='jack')
    # Filter children by gender
    jack = john.child_set.filter(gender='F')
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started using R and am still getting used to its data
I am using this css to format two columns but I am still getting
I'm still getting the hang of working in a threaded environment using NSOperation ,
I'm still getting the hang of Rails. Here I'm using Rails 3 and the
I have tried a couple other similar posts but am still getting an error.
I am still getting started with Unity, and have what seems to be a
I'm still getting used to SQL, so before I get to using stored procedure,
I'm still getting the hang of more advanced MySQL queries, so bear with me
I'm still getting used to the whole Controller flow of iPhone development. I'm using
I think i'm getting closer but still getting resource errors with this. I have

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.