Friday, January 21, 2022

Re: order_by on the basis of time difference (updated_at - created_at)

This is nice idea, but I can't change the model, as discussed by teammates, i need to figure out any other way to do it on the go.


On Fri, Jan 21, 2022 at 5:02 PM Lalit Suthar <sutharlalit.97@gmail.com> wrote:
won't be possible like this, It will be easy if you have another entry in models which stores the difference between updated and created.
You can update that field whenever an object is updated. And then can run order_by on that field directly


On Fri, 21 Jan 2022 at 10:24, Aadil Rashid <aadil10121998@gmail.com> wrote:
class ExampleModel(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
ExampleModel.objects.all().order_by('updated_at' - 'created_at')
but this is not working
it throws, TypeError: unsupported operand type(s) for -: 'str' and 'str'


Django Family 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/CAAYXZx8sABKuJn5Q1ATeHnYsrixfU9wTH_TtPYoR5%3DeAd8DOzA%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/CAGp2JVGL_PbFQZTwCQ_uCLakdwY-54rEz8NpEmrjvGbGjdkM5w%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/CAAYXZx9UZN9ZVuRPk%2BjKdBruA_NUrqwqaDgd7cQZM-HYW-%3Dj8w%40mail.gmail.com.

No comments:

Post a Comment