
from django.contrib import admin
from django import forms
from django.contrib.contenttypes.generic import GenericTabularInline, BaseGenericInlineFormSet

from models import ImageOfModel

class ImageFormset(BaseGenericInlineFormSet):
    
    def clean(self):
        if not self.files.values() and not self.instance.images.all():
            raise forms.ValidationError(u'Загрузите хотябы одну фотографию')

class ImageOfModelInline(GenericTabularInline):
    model = ImageOfModel
    formset = ImageFormset
    extra = 1

from django.contrib import admin
from django import forms
from django.contrib.contenttypes.generic import GenericTabularInline, BaseGenericInlineFormSet

from models import ImageOfModel

class ImageFormset(BaseGenericInlineFormSet):
    
    def clean(self):
        if not self.files.values() and not self.instance.images.all():
            raise forms.ValidationError(u'Загрузите хотябы одну фотографию')

class ImageOfModelInline(GenericTabularInline):
    model = ImageOfModel
    formset = ImageFormset
    extra = 1


class OptionalImageOfModelInline(GenericTabularInline):
    model = ImageOfModel
    extra = 1
Add class OptionalImageOfModelInline for optional images
[+] Add class OptionalImageOfModelInline for optional images

  
  from django.contrib import admin
  from django import forms
  from django.contrib.contenttypes.generic import GenericTabularInline, BaseGenericInlineFormSet
  
  from models import ImageOfModel
  
  class ImageFormset(BaseGenericInlineFormSet):
      
      def clean(self):
          if not self.files.values() and not self.instance.images.all():
              raise forms.ValidationError(u'Загрузите хотябы одну фотографию')
  
  class ImageOfModelInline(GenericTabularInline):
      model = ImageOfModel
      formset = ImageFormset
      extra = 1
+ 
+ 
+ class OptionalImageOfModelInline(GenericTabularInline):
+     model = ImageOfModel
+     extra = 1
Add class OptionalImageOfModelInline for optional images
## Code Before:

from django.contrib import admin
from django import forms
from django.contrib.contenttypes.generic import GenericTabularInline, BaseGenericInlineFormSet

from models import ImageOfModel

class ImageFormset(BaseGenericInlineFormSet):
    
    def clean(self):
        if not self.files.values() and not self.instance.images.all():
            raise forms.ValidationError(u'Загрузите хотябы одну фотографию')

class ImageOfModelInline(GenericTabularInline):
    model = ImageOfModel
    formset = ImageFormset
    extra = 1
## Instruction:
Add class OptionalImageOfModelInline for optional images
## Code After:

from django.contrib import admin
from django import forms
from django.contrib.contenttypes.generic import GenericTabularInline, BaseGenericInlineFormSet

from models import ImageOfModel

class ImageFormset(BaseGenericInlineFormSet):
    
    def clean(self):
        if not self.files.values() and not self.instance.images.all():
            raise forms.ValidationError(u'Загрузите хотябы одну фотографию')

class ImageOfModelInline(GenericTabularInline):
    model = ImageOfModel
    formset = ImageFormset
    extra = 1


class OptionalImageOfModelInline(GenericTabularInline):
    model = ImageOfModel
    extra = 1