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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:10:37+00:00 2026-05-21T09:10:37+00:00

I have a Django object called Family. Family has the variable children, which is

  • 0

I have a Django object called “Family”. “Family” has the variable “children”, which is a many to many field of a class called “Child”.

If I have a “Child” object, is there a way I get the family object to which the child belongs?

Child
      some more fields...
Family
      children = models.ManyToManyField(Child)
      some more fields...

  • 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-21T09:10:38+00:00Added an answer on May 21, 2026 at 9:10 am

    Django automatically creates a reverse relationship for you in this case, so with an instance of the Child model, you can find all Family instances to which the child belongs:

    c = Child.objects.get(id=1)
    c.family_set.all()  # gives you a list of Families
    

    Since it’s unlikely a child will belong to multiple families, though, this isn’t really a Many-to-Many situation. You may wish to consider modelling the relationship on a child object:

    class Family(models.Model):
        pass # your fields here
    
    class Child(models.Model):
        family = models.ForeignKey(Family)
    

    This way, you can get the family for a child using mychild.family, and get all the children in a family using django’s automatic reverse relationship myfamily.child_set.all().

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

Sidebar

Related Questions

I a have a django form which is a select field called piece which
I have a Django Queryset object called data containing string keys and float values.
I have the following code in django.template: class Template(object): def __init__(self, template_string, origin=None, name='<Unknown
In django, I have a form being called from the view, which is passed
I have a django model with a DateTimeField called when which I want to
A python/django beginner's question: I have a datetime object (drive_date), a time object (start_time)
I use the django comments from contrib and I have an object (entry) that
django guardian https://github.com/lukaszb/django-guardian is a really well written object-level permissions app; and I have
I have a list of objects from a django queryset, e.g. my_list = MyObject.objects.filter(variable=something)
I've created a simple 'favourites' system in my django app. I have events which

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.