hi,
I've got the Category model and SearchForm form shown below. I'd like
to customize the way the Category field is rendered in my form in
order 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
-show the hierarchy of my category instances
How can I do that? Do I have to do a custom
forms.CheckboxSelectMultiple()? If so, how can I access Category's
parents and type?
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)
--
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.