views:

44

answers:

1

Example

class Base():
     pass

class A(Base)
parent=models.Foreignkey("self", limit_choices_to=(all members of the B class)

class B(Base)
parent=models.Foreignkey("self", limit_choices_to=(all members of the A class)

What would be the query syntax for limit_choices_to, to get only the objects of a certain class?)

+1  A: 

Wouldn't this work instead ?

class Base(Model):
    parent=models.Foreignkey("self")

    class Meta:
        abstract = True


class A(Base):
    parent=models.Foreignkey("B")

class B(Base):
    parent=models.Foreignkey("A")
sebpiq
Yes, I don't think the OP's code would work at all - `self` is not `Base`, it is `A` or `B`.
Daniel Roseman
You are right, the code I posted is wrong. What I want is something like sebplq's response (which I dont think works either because you cannot override child fields), but maintaining the parent foreign key and just filtering the available choices for the A and B classes. Is there a way to do that?
class Base(Model): parent=models.Foreignkey("self")When you do this and inherit, self is Base, and A or B. What I want is to limit the choices to certain class name only for the admin.
Have you tried the code I posted ?
sebpiq
Yes, you cannot override parent fields in django...