
from django import forms
from django.utils.translation import ugettext_lazy as _

from categories.models import Category


class CategoryForm(forms.ModelForm):
    class Meta:
        model = Category
        fields = '__all__'
        labels = {
            'name': _("Name")
        }


from django import forms
from django.utils.translation import ugettext_lazy as _

from categories.models import Category


class CategoryForm(forms.ModelForm):
    class Meta:
        model = Category
        fields = '__all__'
        labels = {
            'name': _("Name")
        }
        widgets = {
            'name': forms.TextInput(attrs={'required': 'required'}),
        }

Add required attribute to Category name input
Add required attribute to Category name input

  
  from django import forms
  from django.utils.translation import ugettext_lazy as _
  
  from categories.models import Category
  
  
  class CategoryForm(forms.ModelForm):
      class Meta:
          model = Category
          fields = '__all__'
          labels = {
              'name': _("Name")
          }
+         widgets = {
+             'name': forms.TextInput(attrs={'required': 'required'}),
+         }
  
Add required attribute to Category name input
## Code Before:

from django import forms
from django.utils.translation import ugettext_lazy as _

from categories.models import Category


class CategoryForm(forms.ModelForm):
    class Meta:
        model = Category
        fields = '__all__'
        labels = {
            'name': _("Name")
        }

## Instruction:
Add required attribute to Category name input
## Code After:

from django import forms
from django.utils.translation import ugettext_lazy as _

from categories.models import Category


class CategoryForm(forms.ModelForm):
    class Meta:
        model = Category
        fields = '__all__'
        labels = {
            'name': _("Name")
        }
        widgets = {
            'name': forms.TextInput(attrs={'required': 'required'}),
        }
