Hi,
I have three models as
class Category(models.Model):
name = models.CharField(max_length=128)
class SubCategory(models.Model):
category = models.ForeignKey(Category)
name = models.CharField(max_length = 400)
class Document(models.Model):
category = models.ForeignKey(Category, null=True, blank=True,
help_text=_('Required'))
subcategory = models.ForeignKey(SubCategory, null=True, blank=True,
help_text=_('Required'))
title = models.CharField(max_length=300)
Now in Admin interface I have category, subcategory and title field.
If a user is trying to select any subcategory then only that
subcategory item should be displayed which are related to Category.
A simple example is Country, state dropdown.
I am trying to get it from Modelform like
class DocumentAdminModelForm(ModelForm):
def __init__(self, *args, **kwargs):
super(DocumentAdminModelForm, self).__init__(*args,
**kwargs)
self.fields['sub_category'] =
forms.ModelChoiceField(queryset =
SubCategory.objects.filter(category__id = self.fields['category'] ))
but it is not working. Should I use some ajax and jquery for this or
is there any other way you can suggest ??
Thanks
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.