J
J
junqed2011-09-17 14:06:28
Django
junqed, 2011-09-17 14:06:28

Django and ForeignKey?

There is this model:

class Menu(models.Model):                                                                                                                                <br>
    name = models.CharField(max_length=255)<br>
    ....                                                                                  <br>
    parent = models.ForeignKey('self', null=True, blank=True)

I make a selection: this results in a query with a join like this:
menu = Menu.objects.filter(parent__isnull=True)
SELECT "menu_menu".*<br>
FROM "menu_menu"<br>
    LEFT OUTER JOIN "menu_menu" T2 ON ("menu_menu"."parent_id" = T2."id")<br>
WHERE T2."id" IS NULL<br>

that is, djanga thinks that parent in this case is not a field, but another model. I've tried adding related_name but to no avail. Does anyone know what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2011-09-17
@un1t

I often saw a picture when the Dzhang ORM generates such requests. Alternatively, you can write a raw query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question