Thursday, January 20, 2022

Re: Order_by on the basis of time difference:

i can user django user 

Aadil Rashid <aadil10121998@gmail.com>, 21 Oca 2022 Cum, 07:35 tarihinde şunu yazdı:
class UserModel(models.Model):
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)



I want to query on UserModel such that the Query set which I get should be orderable in terms of time difference of updated_at - created_at,
I tried
UserModel.objects.all().order_by('updated_at' - 'created_at')
but this is not working
it throws, TypeError: unsupported operand type(s) for -: 'str' and 'str'


Please help

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAYXZx-sDuJDbTR59bSzmuXfYnHNFUexUd-O%2BfSi9MN%3DG%2Bae6w%40mail.gmail.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGqp9on_hSOUtXFyCRACHRHyVuuLN_BJF5Kd_74KEEEXw299Sw%40mail.gmail.com.

No comments:

Post a Comment