Recursive model queries

ยอดดู 22 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Shekar Tippur

ยังไม่อ่าน,
26 ส.ค. 2558 03:47:3926/8/58
ถึง Django users

Hello,


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
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ