Sort list of items in Django

Posted by mridang on Stack Overflow See other posts from Stack Overflow or by mridang
Published on 2010-04-17T10:05:41Z Indexed on 2010/04/17 10:13 UTC
Read the original article Hit count: 553

Hi Guys,

I have a Django view called change_priority. I'm posting a request to this view with a commas separated list of values which is basically the order of the items in my model. The data looks like this:

1,4,11,31,2,4,7

I have a model called Items which has two values - id and priority. Upon getting this post request, how can I set the priority of the Item depending upon the list order. So my data in the db would look like.

1,1
4,2
11,3
31,4
2,5
4,6
7,7

Thanks guys.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-views