from django.forms.models import inlineformset_factory
from django.forms import ModelForm

from product.models import Product, Photo


class ProductForm(ModelForm):
    class Meta:
        model = Product
        exclude = ['sale_quantity', 'sale_amount', 'in_stock', 'off_shelf']


class PhotoForm(ModelForm):
    class Meta:
        model = Photo
        fields = ['image', 'description']


PhotoFormSet = inlineformset_factory(Product, Photo, form=PhotoForm)
@@ -8,276 +8,861 @@
 ango
-.forms.models import inlineformset_factory%0Afrom django.forms import ModelForm%0A%0Afrom product.models import Product, Photo%0A%0A%0Aclass ProductForm(ModelForm):%0A    class Meta:%0A        model = Product%0A        exclude = %5B'sale_quantity', 'sale_amount', 'in_stock', 'off_shelf'%5D
+ import forms%0Afrom django.forms import ModelForm%0Afrom django.forms.models import inlineformset_factory%0Afrom sorl.thumbnail.admin.current import AdminImageWidget%0A%0Afrom product.models import Product, Photo%0A%0A%0APRODUCT_STATUS = (%0A    ('NORMAL', 'In stock'),%0A    ('OUT-OFF-STOCK', 'Out of stock'),%0A    ('OFF-SHELF', 'Off shelf')%0A)%0A%0A%0Aclass ProductForm(ModelForm):%0A    class Meta:%0A        model = Product%0A        exclude = %5B'sale_quantity', 'sale_amount', 'in_stock', 'off_shelf'%5D%0A%0A    status = forms.ChoiceField(choices=PRODUCT_STATUS, initial=PRODUCT_STATUS%5B0%5D)%0A%0A    def save(self, commit=True):%0A        product = super().save(commit=False)%0A%0A        status = self.cleaned_data%5B'status'%5D%0A        product.in_stock = status != 'OUT-OFF-STOCK'%0A        product.off_shelf = status == 'OFF-SHELF'%0A%0A        if commit:%0A            product.save()%0A        return product
 %0A%0A%0Ac
@@ -968,16 +968,62 @@
 ption'%5D%0A
+        widgets = %7B'image': AdminImageWidget%7D%0A
 %0A%0APhotoF

set product status (buggy)