Reputation: 1
I am sorting a queryset to show tasks with due date closest to/past current date to show first but sort tasks with no due dates to the bottom of the list. My code works in development using sqlite3 but when I deploy it to my shared hosting site with a MySQL backend, sorting does not work. There is no error message, it just won't sort.
My model:
task_name = models.CharField(max_length=100)
task_description = models.TextField(max_length=2000, blank=True, null=True)
due_date = models.DateField(null=True, blank=True)
date_completed = models.DateTimeField(null=True, blank=True)
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.SET_NULL, related_name='workorders_assigned', blank=True, null=True)
completed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, related_name='workorders_completed', blank=True, null=True)
isDeleted = models.BooleanField(default=False)
The code I used to sort the due date are:
workorders = workorders.extra(select ={'custom_dt': 'date(due_date)'}).order_by(F('due_date').asc(nulls_last=True))
and
workorders = workorders.extra(select={'date_is_null': 'due_date IS NULL',}, order_by=['date_is_null', 'due_date'])
both worked in development but neither worked when deployed.
Thanks in advance for your help.
Upvotes: -2
Views: 20