On 14/03/07, Krassimir Grozdanov <[EMAIL PROTECTED]> wrote:
> I am a python and Django novice so please excuse me if my question is
> too stupid.
>
> I have 3 models: Regions, Municipalities  and Persons.
> In the admin interface, when editing the Person object, I want to
> limit the choices for the Municipalities based on the Region choice
> (e.g. I want to limit the list only to Municipalities that are in the
> chosen region). Please advice me which is the best way to do that.
>
> Here follow my models:
>
> class Region(models.Model):
>     region = models.CharField(maxlength=128)
>
>     def __str__(self):
>         return self.region
>     class Meta:
>         verbose_name = 'Област'
>         verbose_name_plural = 'Области'
>     class Admin:
>         pass
>
> class Municipality(models.Model):
>     region = models.ForeignKey(Region)
>     municipality = models.CharField(maxlength=128)
>
>     def __str__(self):
>         return self.municipality
>     class Meta:
>         verbose_name = 'Община'
>         verbose_name_plural = 'Общини'
>     class Admin:
>         pass
>
> class Person(models.Model):
>     PERSON_TYPES = (
>         ('Да', 'Юридическо лице'),
>         ('Не', 'Физическо лице')
>     )
>     region = models.ForeignKey(Region, null = True)
>     municipality = models.ForeignKey(Municipality, null = True)
>     name = models.CharField(maxlength=384)
>     type = models.CharField("Юридическо лице", maxlength=8, choices =
> PERSON_TYPES, default = 'Да', radio_admin = True)
>     dnomer = models.CharField(maxlength=16, blank = True)
>     bulstat = models.CharField('БУЛСТАТ', maxlength=16, blank = True)
>     egn = models.CharField('ЕГН', maxlength=10, blank = True)
>     city = models.CharField(maxlength=64)
>     postcode_p = models.CharField(maxlength=16, blank = True)
>     address_p = models.CharField(maxlength=128, blank = True)
>     phone_p = models.CharField(maxlength=64, blank = True)
>
>     def __str__(self):
>         return self.name
>     class Meta:
>         verbose_name = 'Юридическо лице'
>         verbose_name_plural = 'Юридически лица'
>     class Admin:
>         pass

I am afraid that currently, there isn't a out-of-the-box
implementation of that type of filters in the admin panel. It's more
of a true interface for administrators, rather than a proper content
management insterface.

You'll probably have to extend some control and modify the necessary
view from the admin panel, if you want it to go there. If you're using
the newforms admin - it might be easier to write that there.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to