class ImageForm forms ModelForm class Meta model ImageStore def __init

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class ImageForm(forms.ModelForm):
class Meta:
model = ImageStore
def __init__(self, product=None, *args, **kwargs):
super(ImageForm, self).__init__(*args, **kwargs)
if product is not None:
self.product = product
del self.fields['product']
def save(self, id=None, commit=True):
if id is None:
instance = ImageStore(product=self.product)
else:
instance = ImageStore.objects.get(pk=id)
return forms.save_instance(self, instance, commit=commit)