There is also this thread:
http://groups.google.com/group/django-users/browse_thread/thread/a26d805427aa643f/249463a6f63958f7
[]s
Diego Ucha
On 23 maio, 21:56, "Juanjo Conti" <[EMAIL PROTECTED]> wrote:
> I do it with jquery (client side) getJSON funcion (tamplate exmaple):
>
> <!-- JS: cuando cambia la provincia, cargar las localidades correspondientes
> -->
> <script type="text/javascript">
> jQuery(document).ready(function($){
>
> var prefix = "{{ prefix }}"
> var opcionnula = {{ opcionnula }} //incluir la opción
> nula en la lista de localidades y provincias
> var provincia = "#id_" + prefix + "provincia"
> var localidad = "#id_" + prefix + "localidad"
>
> $(provincia).change(carga_localidades)
>
> if (!opcionnula) {
> $(provincia).children("option:first-child").remove()
> $(localidad).children("option:first-child").remove()
> }
>
> function carga_localidades(){
> var id = $(provincia).val()
> $.getJSON('/localidades/provincia/' + id, {},
> function(localidades){
> $(localidad).html('')
> if (opcionnula) {$(localidad).append('<option
> value="">---------</option>')}
> $.each(localidades, function(k, v){
> $(localidad).append('<option value="' +
> localidades[k]["pk"] + '">' + localidades[k]["fields"]["nombre"] +
> '</option>')
> })
> $(localidad).change()
> })
> }})
>
> </script>
>
> This is the view calling when js points to /localidades/provincia/n/
>
> def localidades_por_provincia(request, id_prov=None):
> if id_prov:
> p = Provincia.objects.get(id=id_prov)
> data = serializers.serialize('json', p.localidad_set.all(),
> fields=('nombre'))
> return HttpResponse(data)
> else:
> return HttpResponse(str([]))
>
> --
> Juanjo Conti
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---