{{{#!python
quali_results =
ToxicologyCaseQualitativeResult.objects.filter(case_id=case.id).select_related('test').order_by('test__name')
field_list =
["AMPHS","BARB","BNZ","BE","Ecstasy","METH","6AM","PCP","THC"] #Usually
populated via retrieval of user settings.
if len(field_list) > 0:
field_list = field_list + [q.test.identifier for q in quali_results]
fields = '"'+'","'.join(str(field) for field in field_list)+'"'
field_sql = "FIELD(`identifier`,"+fields+")"
quali_results = quali_results.extra(select={'field_sql' : field_sql},
order_by=['field_sql'])
quali_resultfs = QualitativeResultFormset(queryset=quali_results,
prefix='quali_results')
}}}
If there is a better way to do this, I would be happy to change.
Cheers!
--Brandon
--
Ticket URL: <https://code.djangoproject.com/ticket/28756>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
* component: Uncategorized => Database layer (models, ORM)
Comment:
I think that should be possible by writing your own
[https://docs.djangoproject.com/en/dev/ref/models/expressions/ Query
Expression] -- did you try it? If you have trouble, you can ask for help
on [TicketClosingReasons/UseSupportChannels our support channels]. If that
investigation shows that it's infeasible, please reopen the ticket with
details.
--
Ticket URL: <https://code.djangoproject.com/ticket/28756#comment:1>