I have a model like this
class Category(models.Model): title = models.CharField(max_length=100, db_index=True) slug = models.SlugField(max_length=100, db_index=True) def __str__(self): return "%s"%self.title class Video(models.Model): title = models.CharField(max_length=100, unique=True) slug = models.SlugField(max_length=100, unique=True) idlink = models.CharField(max_length=50) posted = models.DateField(db_index=True, auto_now_add=True) category = models.ForeignKey(Category) def __str__(self): return "%s"%self.title
And my views.py is
def list_video_cat(request, slug): video = Video.objects.filter(category__slug=slug).order_by('-posted') return render(request, 'category.html', {'videos':video})
I want to show my post new to old, but it seems to did not work at this situation. What should I do?
P/S I read this topic before, but it does not solve my problem http://stackoverflow.com/questions/6114718/order-by-doesnt-work-with-filter-in-django-view
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e89357af-054c-43e9-9d8b-a45fbc8f5ae1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment