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

2022-01-23 Thread Aadil Rashid
Thank you very much Django family for your positive response, and especially to *@Fabio C. Barrionuevo da Luz,* Adding another field to the QuerySet using the *"**annotate"* function really helped and solves the problem like a charm! as side by @Lalit Suthar Thank you once again everyone for

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

2022-01-22 Thread DJANGO DEVELOPER
you can use datetime.datetime.strptime to avoid this error. I resolved it few days back. for this you have to import datetime like this: import datetime On Sat, Jan 22, 2022 at 12:19 PM Lalit Suthar wrote: > Fabio C. Barrionuevo da Luz's answer will work like a charm! > > > > On Fri, 21 Jan

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

2022-01-21 Thread Lalit Suthar
Fabio C. Barrionuevo da Luz's answer will work like a charm! On Fri, 21 Jan 2022 at 21:04, Fabio C. Barrionuevo da Luz wrote: > this can be easily solved by using an annotation to calculate the > difference and store it in a new temporary column, and then sort by it > > > from

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

2022-01-21 Thread Fabio C. Barrionuevo da Luz
this can be easily solved by using an annotation to calculate the difference and store it in a new temporary column, and then sort by it from django.db.models import F from myapp.models import ExampleModel queryset = ExampleModel.objects.annotate( dt_difference=F('updated_at') -

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

2022-01-21 Thread Gabriel Araya Garcia
Try this: ExampleModel.objects.all().order_by('updated_at' , '-created_at') Gabriel Araya Garcia GMI - Desarrollo de Sistemas Informáticos El vie, 21 ene 2022 a las 1:54, Aadil Rashid () escribió: > class ExampleModel(models.Model): > is_active = models.BooleanField(default=True) > created_at

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

2022-01-21 Thread Feroz Ahmed
Hi, in VIEWS def example=(request): fm=ExampleModel.object.created_at ExMd=ExampleModel.objects.filter(created_at__lt={'fm'})... ordering conditions. On Friday, January 21, 2022 at 10:25:13 AM UTC+5:30 aadil1...@gmail.com wrote: > class ExampleModel(models.Model): > is_active =

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

2022-01-21 Thread Aadil Rashid
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 wrote: > won't be possible like this, It will be easy if you have another entry in > models which stores the

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

2022-01-21 Thread Lalit Suthar
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 wrote: