class CategoryForm forms Form slug forms CharField max_length 255 labe

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class CategoryForm(forms.Form):
slug = forms.CharField(max_length=255, label=_('slug'), required=False)
title = forms.CharField(max_length=255, label=_('title'))
short_description = forms.CharField(max_length=255, help_text=_('255 chars maximum'), label=_('short description'))
long_description = forms.CharField(max_length=65000, label=_('long description'), widget=forms.Textarea)
metadata_description = forms.CharField(max_length=255, label=_('metadata'), widget=forms.Textarea, help_text=_('255 chars maximum'))
metadata_keywords = forms.CharField(label=_('keywords'), max_length=255, widget=forms.Textarea, help_text=_('255 chars maximum'))
def save(self, id=None, commit=True):
if id is None:
cat = ProductCategory()
trans = Translation()
else:
cat = ProductCategory.objects.get(pk=id)
ct = ContentType.objects.get_for_model(ProductCategory)
try:
trans = Translation.objects.get(content_type=ct, object_id=id)
except Translation.DoesNotExist:
trans = Translation(content_object=cat)
return form.models.save_instance(self, cat, commit=commit), form.models.save_instance(self, trans, commit=commit)