from django import forms
from ...product.models import Collection


class CollectionForm(forms.ModelForm):
    class Meta:
        model = Collection
        exclude = []

from unidecode import unidecode

from django import forms
from django.utils.text import slugify

from ...product.models import Collection


class CollectionForm(forms.ModelForm):
    class Meta:
        model = Collection
        exclude = ['slug']

    def save(self, commit=True):
        self.instance.slug = slugify(unidecode(self.instance.name))
        super(CollectionForm, self).save(commit=commit)
        return self.instance

Update CollectionForm to handle slug field
Update CollectionForm to handle slug field

+ from unidecode import unidecode
+ 
  from django import forms
+ from django.utils.text import slugify
+ 
  from ...product.models import Collection
  
  
  class CollectionForm(forms.ModelForm):
      class Meta:
          model = Collection
-         exclude = []
+         exclude = ['slug']
  
+     def save(self, commit=True):
+         self.instance.slug = slugify(unidecode(self.instance.name))
+         super(CollectionForm, self).save(commit=commit)
+         return self.instance
+ 
Update CollectionForm to handle slug field
## Code Before:
from django import forms
from ...product.models import Collection


class CollectionForm(forms.ModelForm):
    class Meta:
        model = Collection
        exclude = []

## Instruction:
Update CollectionForm to handle slug field
## Code After:
from unidecode import unidecode

from django import forms
from django.utils.text import slugify

from ...product.models import Collection


class CollectionForm(forms.ModelForm):
    class Meta:
        model = Collection
        exclude = ['slug']

    def save(self, commit=True):
        self.instance.slug = slugify(unidecode(self.instance.name))
        super(CollectionForm, self).save(commit=commit)
        return self.instance
