Django - Way of writing a generic create view

Hello. In my project, I write a create view like so:

class ArticleCreateView(CreateView):
    form_class = ArticleModelForm
    template_name = 'article_create.html'
    success_url = reverse_lazy('article_list')

Here is the form:
class ArticleModelForm(forms.ModelForm):
    class Meta:
        model = Article
        fields = ['title', 'description']

    def clean_title(self):
        data = self.cleaned_data.get('title')

        if len(data) < 4:
            raise forms.ValidationError('Please')

        return data

In the documentation, the way to create a Generic CreateView is like so (without creating a model form):

class ArticleCreateView(CreateView):
    model = Article
    fields = ['title', 'description']
    template_name = 'article_create.html'
    success_url = reverse_lazy('article_list')

What is the difference between these two ways of creating a generic create view, which is the better way to do so. Also with the first implementation, to add field validation, I can add the clean method to raise a form validation error if necessary. How would I do this with the second implementation shown above (how would I add field validation in the example above). Thanks.

The documented ArticleCreateView defines model and fields to shortcut the creation of the form. Under the hood, the CreateView class creates a form class from the model and fields. With this way, there’s no way of customizing the clean() method, or anything else in the form.

The form-creating behaviour is defined in ModelFormMixin.

@adamchainz Ah ok. So when you want to add things like the clean method, you should define
form_class instead of the model and fields properties?

Exactly. model and fields are shortcuts - and perhaps not very useful ones since they save you just a couple lines of code ot create a class.