A
A
Argumentsite2020-07-30 13:41:02
Django
Argumentsite, 2020-07-30 13:41:02

Why doesn't Django Paginate paginate objects for DetailView with MultipleObjectMixin?

Good afternoon!

There was a need to make pagination for DetailView in Django. Googling, I found out that this can be done using MultipleObjectMixin. The result is this:

views.py

class BuyDetailView(DetailView, MultipleObjectMixin):
model = CarsBuy
template_name = 'cars/cars_buy_detail.html'
slug_field = 'cars_buy_url'
paginate_by = 10

def get_context_data(self, **kwargs):
    object_list = Cars.objects.filter(cars_buy=self.get_object())
    context = super(BuyDetailView, self).get_context_data(object_list=object_list, **kwargs)
    return context


models.py

class CarsBuy(models.Model):
    cars_buy = models.CharField("Купить", max_length=50, unique=True)

class Cars(models.Model):
    cars_buy = models.ManyToManyField(CarsBuy, verbose_name="Купить", blank=True, related_name='cars_buy_rn')


Pagination is showing up. But instead of paginating objects, each pagination page displays the full list of objects in the same way. Tell me, please, what could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question