Wednesday, August 26, 2015

Recursive model queries


Hello,

I am trying to use https://github.com/heywbj/django-rest-framework-recursive

I need to be able to run query on a recursive model that gives the name of the parent and child

My model

class RecursiveModel(models.Model):
   stage_title = models.CharField(max_length=255, unique=True)
    parent = models.ForeignKey('self', null=True)

I need to get the names of parent and child relationship
Equivalant query being:

select c.id, c.stage_title as child, p.stage_title as parent from recursivemodel c, recursivemodel p  where c.parent_id=p.id

How do I do that?

When I run it, I get:

Cannot assign "'stgabc'": "RecursiveModel_Deferred_created_data_parent_id_stage_title.parent" must be a "RecursiveModel" instance.

- Shekar

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/26e3b1e5-5ba9-4959-9a36-52cc35d33ca7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment