hi,
I've got the Category model and SearchForm form shown below. I'd like to do 2 things in my template:
-to separate in the form the Category instances having a given type to be able to apply a specific style to them in my CSS
-to show the hierarchy of my category instances
Basically I need to access the Category's parent and style in my template or to modify the rendering of my form. How can I do this? thanks Jul
Category model
CATEGORY_TYPE = [
(1, 'region'),
(2, 'type'),
]
class Category(models.Model):
parent = models.ManyToManyField('self', symmetrical=False, null=True, blank=True)
type = models.PositiveSmallIntegerField(choices=CATEGORY_TYPE)
class Translation(multilingual.Translation):
name = models.CharField(max_length=100, unique=True)
class Meta:
verbose_name_plural = 'Categories'
def __unicode__(self):
return "%s" %(self.name)
SearchForm class
class SearchForm(forms.Form):
query = forms.CharField(max_length=100, required=False)
price_range = forms.IntegerField(widget=forms.Select(choices = PRICE_RANGES_AND_EMPTY), required=False)
def __init__(self, *args, **kwargs):
super(SearchForm, self).__init__(*args, **kwargs)
self.fields['country'] = forms.ModelChoiceField(queryset=Country.objects.all().order_by('name'), empty_label='All', required=False)
self.fields['category'] = forms.ModelMultipleChoiceField(queryset=Category.objects.all().order_by('name'),
widget=forms.CheckboxSelectMultiple(), required=False)