Answer the question
In order to leave comments, you need to log in
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
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')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question