Answer the question
In order to leave comments, you need to log in
How to pass self to filter for Django views?
models
class Product(models.Model):
article = models.CharField('Артикул', max_length=100)
name = models.CharField('Наименование', max_length=100)
poster = models.ImageField('Постер', upload_to='products/posters/')
description = models.TextField('Описание')
category = models.ForeignKey(
Category, verbose_name='Категория', on_delete=models.SET_NULL, null=True)
price = models.PositiveIntegerField(
'Цена', default=0, help_text='Указывать сумму в рублях')
hide = models.BooleanField('Скрыть', default=False)
slug = models.SlugField(max_length=160, unique=True)
class ProductDetailView(DetailView):
module = Product
queryset = Product.objects.filter(hide=False)
template_name = 'products/single-product.html'
def get_last_products(self):
return Product.objects.filter(category=self.product.category) #Вот ТУТ
{% for last_product in view.get_last_products %}
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