In general, when I experimented with the capabilities of Django, I had a question how I can add a queue for model records, for example, I have a couple of blocks and I need to display the model that was registered first and on the second block it should be displayed next entry. How can I do this?
here is an example query_set
class IndexView(generic.ListView):
template_name = 'article/sale.html'
model = Goods
context_object_name = 'goods'
def get_queryset(self):
return Goods.objects.order_by('-pub_date')[:1]
In html, I output the entry like this
{% for good in queryset %}
<h1 class="price" >{{ good.price2_text }}</h1>
{% endfor %}
this is code of models.py
class Goods(models.Model):
description_text = models.CharField(max_length=200)
price_text = models.CharField(max_length=200)
image_sale = models.ImageField(blank=True, upload_to='images/')
description1_text = models.CharField(max_length=200)
price1_text = models.CharField(max_length=200)
image1_sale = models.ImageField(blank=True, upload_to='images/')
description2_text = models.CharField(max_length=200)
price2_text = models.CharField(max_length=200)
image2_sale = models.ImageField(blank=True, upload_to='images/')
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.description_text
def __str__(self):
return self.price_text
def __str__(self):
return self.description1_text
def __str__(self):
return self.price1_text
def __str__(self):
return self.description2_text
