0

For a property, I can't manage to filter a Queryset with another property. I want that if "father" has "Star" in "True", "star_descendant" returns "father".

I have this error: Exception Value: 'QuerySet' object has no attribute 'star'. How to fix it?

My code :

    @property
    def star(self):
        if Evenements.objects.filter(eventtype=93).filter(xrefindividuproprio=self):
            return True
        return False

    @property
    def star_descendant(self):
        father = Individus.objects.filter(codeid=self.xrefpere_id)
        mother = Individus.objects.filter(codeid=self.xrefmere_id)
        if father.star == True:
            return father
Night18
  • 13
  • 3

1 Answers1

0

In your function, "father" and "mother" are querysets. "star" is a property of an object. You must to get an object. Queryset has no attribute "star".

if Individus.objects.filter(codeid=self.xrefpere_id).count() > 0:
    father = Individus.objects.filter(codeid=self.xrefpere_id).first()
    if father.star == True:
        return father

Or, if codeid is an unique field, then: father = Individus.objects.get(codeid=self.xrefpere_id)

LaCharcaSoftware
  • 1,075
  • 1
  • 5
  • 13