Hi
When I submit my form with no errors it correctly processes and returns
after completing form_valid.
However, when I submit my form with errors I get a django dump stating that
'ShowForumPostsView'
object has no attribute 'object_list'.
I am struggling to make it return to the same page but showing the errors.
Any help would be appreciate please.
Thank you
My code:
class ShowForumPostsView(GroupRequiredMixin, FormMixin, ListView):
model = Post
group_required = 'clients'
paginate_by = 4
form_class = PostForm
....
....
....
def post(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
#return self.get(request, *args, **kwargs)
def form_valid(self, form):
data = form.save(commit=False)
data.creator = self.request.user
data.thread_id = Thread.objects.get(slug=self.kwargs['threadslug']).pk
data.save()
messages.success(self.request, '{0} added.'.format(self.model.__name__))
if self.request.is_ajax():
return JsonResponse({'reset': True})
return super(ShowForumPostsView, self).form_valid(form)
def form_invalid(self, form):
messages.error(self.request, '{0} could not be
saved.'.format(self.model.__name__))
if self.request.is_ajax():
return JsonResponse(form.errors, status=400)
#return super(ShowForumPostsView, self).form_invalid(form)
return self.render_to_response(self.get_context_data(form=form))
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b7322f53-a0dc-4146-b087-87c188130a69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.