I’ve been trying to filter objects in my page by the date they were added, unfortunately I had no success. Maybe the right question is how to iterate over these dates
Models:
class Day(models.Model):
name = models.CharField(max_length=255, default=timezone.localdate(), blank=True)
def str(self):
return self.name
class Sale(models.Model):
value = models.CharField(max_length=25, editable=True, default=‘’)
date_time = models.DateField(default=timezone.now,)
name = models.CharField(max_length=127, editable=True, blank=True, default=‘’)
day = models.ForeignKey(Day, on_delete=models.DO_NOTHING, default=‘’, blank=True)
def str(self):
return self.value
views function
def day_details(request, day_id):
day = get_object_or_404(Day, id=day_id)
sales = Sale.objects.order_by('-id').filter(
Day.name <====
)
return render(request, 'home/day_details.html', {
'day': day,
'sales': sales
})
I tried converting the values to str, using their id, all I want is to filter them by the same date they were added
cannot unpack non-iterable ForwardManyToOneDescriptor object
cannot unpack non-iterable int object
cannot unpack non-iterable DeferredAttribute object