I haven't done it much, but, yeah, ajax is probably best. Maybe something like might work:
-- $('#id_category').change(function(){
var category = $(this).val() // not sure about this. the point is, get the selected id.
$.get('/subcategory-options/?category=' + encodeURIComponent(category), function(data){
$('#id_subcategory').replaceWith(data)
})
})urls.py:
url(r'^subcategory-options/$', views.subcategory_options),views.py:
def subcategory_options(request):
subcategories = SubCategory.objects.filter(category=request.GET['category'])
class TempForm(forms.Form):
field = forms.ModelChoiceField(queryset=subcategories)
form = TempForm()
return render(request, 'subcategory_options.html', {'form': form})subcategory_options.html:
{{ form }}You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/486ce251-7e51-4557-b77e-71270d772cc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment