Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Use in in django while preserving order

pk_list = [5, 7, 1, 3, 4]
clauses = ' '.join(['WHEN id=%s THEN %s' % (pk, i) for i, pk in enumerate(pk_list)])
ordering = 'CASE %s END' % clauses
queryset = Article.objects.filter(pk__in=pk_list).extra(
           select={'ordering': ordering}, order_by=('ordering',))
Comment

PREVIOUS NEXT
Code Example
Python :: medium seaaborn mathplot diesign styles 
Python :: python togli spazio 
Python :: python - retrieve unconnected node pairs 
Python :: jupyter notebook morse code francais 
Python :: pss signatures python 
Python :: check stl file for errors in pyvista 
Python :: 12 hour clock to 24 hour clock in python 
Python :: python event start from file funcion 
Python :: flatten a list of lists python 
Shell :: get cpu frequency linux 
Shell :: copy ssh key mac 
Shell :: conda install seaborn 
Shell :: remove all docker iamges commandl 
Shell :: ubuntu pip3 
Shell :: how to do compress video in linux 
Shell :: uninstall wps office ubuntu 
Shell :: install rest framework 
Shell :: remove google chrome linux 
Shell :: remove remote origin github 
Shell :: serial number linux 
Shell :: install discord module py 
Shell :: ubuntu 20.04 install skype 
Shell :: npm install --global yarn 
Shell :: upgrade ubuntu 
Shell :: bison install ubuntu 
Shell :: How to add username and password in github 
Shell :: check ffmpeg version command 
Shell :: upgrade chocolatey 
Shell :: zsh: no such file or directory: /usr/local/bin/composer.phar 
Shell :: intall teams on ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =