Sorting the searched records

27 views
Skip to first unread message

Khurram Shahzad

unread,
Jul 3, 2017, 1:43:14 AM7/3/17
to try...@googlegroups.com
Dear All,

I am trying to sort the searched records using following code:

roundings = PatientRounding.search([
            ('name', '=', self.name),   
            ], order=[('evaluation_start', 'DESC')])

But, I am not getting the results sorted on 'evaluation_start' field. Infact, the 'order' clause is not affecting the sorting of searched records!

Is this the correct way of sorting the searched records? Or there is some other way of searching for a model and retuning the sorted results?

--
 
Regards,
Khurram.

Jean Cavallo

unread,
Jul 3, 2017, 3:22:52 AM7/3/17
to try...@googlegroups.com
Hi,

2017-07-03 7:43 GMT+02:00 Khurram Shahzad <min2...@gmail.com>:
roundings = PatientRounding.search([
            ('name', '=', self.name),   
            ], order=[('evaluation_start', 'DESC')])

What's the printed output of calling the search with the query=True parameter ?

Jean Cavallo
Coopengo

Sergi Almacellas Abellana

unread,
Jul 3, 2017, 3:31:52 AM7/3/17
to try...@googlegroups.com
El 03/07/17 a les 07:43, Khurram Shahzad ha escrit:
> Dear All,
>
> I am trying to sort the searched records using following code:
>
> roundings = PatientRounding.search([
> ('name', '=', self.name <http://self.name>),
> ], order=[('evaluation_start', 'DESC')])
>
> But, I am not getting the results sorted on 'evaluation_start' field.
> Infact, the 'order' clause is not affecting the sorting of searched records!
>
> Is this the correct way of sorting the searched records? Or there is
> some other way of searching for a model and retuning the sorted results?
Is the correct way.

Which type of field is the evaluation_start? Is it a functional one?
Have you implemented some order_ function to override it?



--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Khurram Shahzad

unread,
Jul 3, 2017, 4:04:56 AM7/3/17
to try...@googlegroups.com
Dear Sergi,
It is not a functional field. And, it is defined as following:


class PatientRounding(ModelSQL, ModelView):
    'Patient Rounding'
    __name__ = 'gnuhealth.patient.rounding'

    STATES = {'readonly': Eval('state') == 'done'}

    name = fields.Many2One('gnuhealth.inpatient.registration', 'Registration Code', required=True, states=STATES)
    code = fields.Char('Code',  states=STATES)
    health_professional = fields.Many2One('gnuhealth.healthprofessional',
        'Health Professional', readonly=True)
    evaluation_start = fields.DateTime('Start', required=True, states=STATES)


Do we need to implement and override order_ function? How can that be done for the above class where I want to sort on 'evaluation_start', the results returned by 'search' method. Please note this sort column is different than that defined in '__setup__()' class method.
--
 
Regards,
Khurram.

Sergi Almacellas Abellana

unread,
Jul 3, 2017, 7:14:28 AM7/3/17
to try...@googlegroups.com
El 03/07/17 a les 10:04, Khurram Shahzad ha escrit:
No it's not required, but it can be used to customize the order, and
this can break the order if not done correctly.

I can not see any other reason to not make it work.


> --
> Regards,
> Khurram.
>
> --
> You received this message because you are subscribed to the Google
> Groups "tryton" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tryton/CAM3N3CwauqXQcLC_NLwx3OKjXLus6DhS4Vem8Q2yUcMw-SqsMA%40mail.gmail.com
> <https://groups.google.com/d/msgid/tryton/CAM3N3CwauqXQcLC_NLwx3OKjXLus6DhS4Vem8Q2yUcMw-SqsMA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages