i am using django 1.2 i have two models.
EDIT: i just found a better example:
class Parent(models.Model):
name = models.CharField(max_length=255)
favorite_child = models.ForeignKey(Child)
class Child(models.Model):
name = models.CharField(max_length=255)
myparent = models.ForeignKey(Parent)
in this example i would like to be able to choose a favorite child but the problem is that the admin will give me all the children to choose from and not just the ones who are the children of the parent i am currently editing.
ORIGINAL EXAMPLE:
class Version(models.Model):
name = models.CharField(max_length = 255)
platform = models.ForeignKey("Platform",related_name='version_platform')
class Platform(models.Model):
name = models.CharField(max_length = 255)
default_version = models.ForeignKey(Version,related_name='platform_default_version')
i want the django admin to limit the drop down when i choose default_version so that i will only be able to choose those versions that have the current platform.
for example if i have version named '1.1' that has platform joomla and version '1.2' that has wordpress as platform.
so when i will choose default_version dropdown in the admin for wordpress i want it to only show me version '1.2' in the drop down. now it shows me all of the versions.
i am trying to limit limit_choices_to as shown here so i try this:
class Platform(models.Model):
name = models.CharField(max_length = 255)
default_version = models.ForeignKey(Version,limit_choices_to={'platform':XXXXX},related_name='platform_default_version')
but i am lost as to what to put insted of the XXXX i try putting self but it did not work.
i have also tried
limit_choices_to={'platform.name':name}
i did not work either.
in this example i would like to be able to choose a favorite child but the problem is that the admin will give me all the children to choose from and not just the ones who are the children of the parent i am currently editing.