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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:57:03+00:00 2026-06-16T00:57:03+00:00

I have two model classes, Person and Relationship as follows with fields omitted for

  • 0

I have two model classes, Person and Relationship as follows with fields omitted for brevity:

class Person(models.Model):
    first_name = models.CharField(max_length=32, null=True)
    .
    .
    .
    relationship = models.ManyToManyField('Relationship', related_name='relative')


class Relationship(models.Model):
    person = models.ForeignKey('Person', related_name='relative', null=True)

Let’s say Person A is a father and Person B is a daughter. I would have create them as follows:

personA = Person()
personA.first_name = "Father"
personA.save()

personB = Person()
personB.first_name = "Daughter"
personB.save()

Then the relationships between them:

daughterRelationship = Relationship()
daughterRelationship.person = personB
daughterRelationship.save()
personA.relationship.add(daughterRelationship)

fatherRelationship = Relationship()
fatherRelationship.person = personA
fatherRelationship.save()
personB.relationship.add(fatherRelationship)

Now, based on my models (maybe related_name=’relative’ is causing the issue), but I can’t seem to figure out my reverse lookup name.

I’ve tried these, but to no avail:

relationship = Relationship.objects.get(id=1)
personA = relationship.person
personB = relationship.relative_set.all().get() # Relationship does not have attribute 'relative_set'
personB = relationship.person_set.all().get() # Relationship does not have attribute 'person_set'
personB = relationship.relationship_set.all().get() # Relationship does not have attribute 'relationship_set'
personB = relationship.personrelationship_set.all().get() # Relationship does not have attribute 'personrelationship_set'
personB = relationship.personrealtive_set.all().get() # Relationship does not have attribute 'personrelative_set'

I can’t seem to get it, can anybody else see what’s going on, or any suggestions? Thanks.

  • 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-16T00:57:04+00:00Added an answer on June 16, 2026 at 12:57 am

    I think this situation is better suited to a recursive relationship of Person to itself through Relationship.

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

Sidebar

Related Questions

I have two very simple classes Submission and Store class Submission(models.Model): title = models.CharField(max_length=50,
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
Here two of my model classes: class DashboardVersion(models.Model): name = models.CharField(_(Dashboard name),max_length=100) description =
I'm using Django and have two classes: class PR(models.Model): Jq = models.ForeignKey(JQ) user =
I have two classes: class Translation(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() object =
I have this two classes: class Person(db.Model): person_name = db.StringProperty(required = True) #gender =
I have two classes (MVC view model) which inherits from one abstract base class.
I have a simple Fluent NHibernate model with two related classes: public class Applicant
I have two model classes: Cars and Customers , Model Cars : class car
I have two Model classes: Attendance and Employee. I have defined the Employee class

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.