Last active
May 12, 2024 17:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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