I am having strange issue with django ordering. For some reason I am not able to order my List View by multiple fields.
Here is my class.
class Syslog(models.Model):
receivedat = models.DateTimeField(default=timezone.now)
facility = models.PositiveSmallIntegerField()
priority = models.PositiveSmallIntegerField()
fromHost = models.CharField(max_length=50)
message = models.TextField(max_length=500)
class Meta:
ordering = ['id','receivedat', 'fromHost']
Here is my view class as well:
class HomePageView(ListView):
model = Syslog
template_name = 'home.html'
context_object_name = 'all_logs'
paginate_by = 10
ordering = ['-id', 'receivedat', 'fromHost']
When a single field in ordering is specified (e.g. ordering = ['-id']), but when I add a second or third parameter everything goes back to defaults (only the first field of ordering is getting recognized)
Does anyone have encounter a similar problem?
The same problem persists in the Django shell as well. When I execute the following query Syslog.objects.all().order_by('id') everything looks good, but when I add another field to order_by (e.g. Syslog.objects.all().order_by('id','fromHost')) the second field doesn't get recognized at all.
Regards, Jordan