Re: Custom ManyToManyField widget in admin

2007-11-23 Thread kamil
congrats. interesting solution. Lately I've switched to newforms admin too. On Nov 22, 11:50 am, Julien <[EMAIL PROTECTED]> wrote: > Hi Kamil and all, > > I have finally found what I was looking for by using the branch > newforms-admin. > It could be tidied up a bit, but at least it works! > Hope

Re: Custom ManyToManyField widget in admin

2007-11-22 Thread Julien
Hi Kamil and all, I have finally found what I was looking for by using the branch newforms-admin. It could be tidied up a bit, but at least it works! Hope that will help others. (Note: all this led me to some other questions, which I have posted there: http://groups.google.com/group/django-user

Re: Custom ManyToManyField widget in admin

2007-11-21 Thread kamil
sorry line "{{ group.grouper.name }}: [ shoud be: "{{ group.grouper.name }}": [ On Nov 21, 11:49 am, kamil <[EMAIL PROTECTED]> wrote: > Hi Julien > > in fact you don't even have to write view for it you can use generic > view as follows: > > put in your url.py: >

Re: Custom ManyToManyField widget in admin

2007-11-21 Thread kamil
Hi Julien in fact you don't even have to write view for it you can use generic view as follows: put in your url.py: --- from yourproject.cities.models import City urlpatterns = patterns('', .. (r'^custom_widget.js', 'django.views.generic.list_de

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread Julien
Thanks again Kamil for your help! Ok, now I'm trying to put everything together. Sorry I'm just starting with Django and I am still a bit lost. What I am not sure about is: - where to put the view? - how to hook the view to the model - how to hook the template with the view. Could you provide a

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread kamil
You would achieve it using "regroup" template tag First get cities in your view and create template with code: var countries = { {% regroup cities by country as grouped %} {% for group in grouped %} "{{ group.grouper.name }}: [ {% for city i

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread Julien
Hi, When I look at the html source code generated for the regular ManyToManyField's widget, it's an html form, not javascript... Are you sure there is no other way? Could you please give a full example? I've spent quite sometime practicing with the tutorials but I'm a bit lost on this one. Tha

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread kamil
I dont think there is another way that making your hands dirty with javascript. ;) If you want to be fancy you can even make it ajax - getting the cities on demand On Nov 20, 9:35 am, kamil <[EMAIL PROTECTED]> wrote: > You can easily generate cities list to the javascript dynamically > writing th

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread kamil
You can easily generate cities list to the javascript dynamically writing the template for separate js file. On Nov 20, 9:22 am, Julien <[EMAIL PROTECTED]> wrote: > Hi Kamil, > > Thanks a lot for your suggestion! > > I have a few remarks though. The list of cities is dynamic, in the > sense tha

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread kamil
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.onchan

Re: Custom ManyToManyField widget in admin

2007-11-20 Thread Julien
Hi Kamil, Thanks a lot for your suggestion! I have a few remarks though. The list of cities is dynamic, in the sense that you may add, remove cities from the database at any time using the admin interface. So how can we fetch dynamically the list of available cities to display them in the select

Re: Custom ManyToManyField widget in admin

2007-11-19 Thread Julien
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 <

Custom ManyToManyField widget in admin

2007-11-19 Thread Julien
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__(se