Skip to content

Instantly share code, notes, and snippets.

@AndreasDickow
Last active May 12, 2024 17:25
Show Gist options
  • Save AndreasDickow/695b3f64da9d7ad93fa363b2e2e5b8a8 to your computer and use it in GitHub Desktop.
Save AndreasDickow/695b3f64da9d7ad93fa363b2e2e5b8a8 to your computer and use it in GitHub Desktop.
Fix object has no attribute 'object_list' when post create duplicate in Django-Tables2 ListView
class mylist(SingleTableMixin, FilterView):
...
def get_context_data(self, **kwargs):
queryset = kwargs.pop('object_list', None)
if queryset is None:
self.object_list = self.model.objects.all()
...
return super().get_context_data(**kwargs)
def post(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid():
instance = form.save(commit=False)
...
instance.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
@Nissanx
Copy link

Nissanx commented May 12, 2024

views.py
I've got the same issue no object_list appears on ListView.
I tried the above code, and I expected, there would be duplicates, as I am working on both: Django.views.generic.base import TemplateView, and: Django.views.generic.list import ListVies. the problem is not resolved! unfortunetaly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment