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.