Hi Julien

The simple way is hijack city select box with javascript.
You add
js=['http://here comes path to your script']
to admin options in your model
js can look like this:

var countries = {'england': ['London','Manchester'], 'france':
['Paris'] }

document.forms['your_form'].id_country.onchange = function()
{ listCities(this.value) };

function listCities ( country ) {
    document.forms['your_form'].id_city.options.length = 0
    var l = countries[ country ].length;
    for (var i = 0; l > i; i++) {
        document.forms['your_form'].id_city.options[i] = new
Option( countries[ country ][i], countries[ country ][i]);
    }
}

I hope it helps :)

On Nov 19, 11:54 pm, Julien <[EMAIL PROTECTED]> wrote:
> Sorry, my "drawing" came out a bit funny in my previous post. Here's
> what I'd like the custom widget to look like:
>
> England
>     [  ] London   [  ] Manchester
> France
>     [  ] Paris
> Russia
>     [  ] Moscow
> USA
>     [  ] Los Angeles   [  ] New York
>
> Thanks for your help!
>
> On Nov 20, 10:51 am, Julien <[EMAIL PROTECTED]> wrote:
>
> > Hi all,
>
> > I'm a Django newbie, and I've been struggling on this for days. I've
> > also found posts on this group about similar subjects but none that
> > could directly help me...
>
> > Here are the models I've got:
>
> > class Country(models.Model):
> >     name = models.CharField(max_length=50)
> >     def __unicode__(self):
> >         return self.name
> >     class Admin:
> >         pass
>
> > class City(models.Model):
> >     name = models.CharField(max_length=50)
> >     country = models.ForeignKey(Country)
> >     def __unicode__(self):
> >         return self.name
> >     class Admin:
> >         pass
>
> > class Person(models.Model):
> >     firstName = models.CharField(max_length=30)
> >     lastName = models.CharField(max_length=30)
> >     citiesLived = models.ManyToManyField(City, null=True, blank=True)
> >     def __unicode__(self):
> >         return self.firstName + " " + self.lastName
> >     class Admin:
> >         pass
>
> > In the admin interface, when adding cities to a person's profile, you
> > get the usual ManyToMany select box.
>
> > So you may have:
> > New York
> > Manchester
> > Paris
> > London
> > Moscow
> > Los Angeles
>
> > What I'd like to get instead is a custom widget, that is a list of
> > checkboxes sorted by country, and in Alphabetic order. E.g.:
> > ________________________________________
> > |
> > England
> > |
> > |    [  ] London   [  ]
> > Manchester                                      |
> > |
> > France
> > |
> > |    [  ]
> > Paris
> > |
> > |
> > Russia
> > |
> > |    [  ]
> > Moscow
> > |
> > |
> > USA
> > |
> > |    [  ] Los Angeles   [  ] New York
> > |
> > |_______________________________________|
>
> > Could you give me some advice on how to implement that?
>
> > Many thanks!!
>
> > Julien
--~--~---------~--~----~------------~-------~--~----~
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