code_junkie

in SQL, or Django ORM, what's the conventional way to have an ordered one-to-many?

Nov 13th, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. {% extends 'admin/change_form.html' %}
  2.  
  3. {% block form_top %}{% endblock %}
  4. {% block extrahead %}{{ block.super }}
  5. <script type="text/javascript" src="/media/js/jquery.js"></script>
  6. <script type="text/javascript" src="/media/js/interface.js"></script>
  7. <script>
  8. $(document).ready(
  9. function () {
  10. $('ol.articles').Sortable(
  11. {
  12. accept : 'sortableitem',
  13. helperclass : 'sorthelper',
  14. activeclass : 'sortableactive',
  15. hoverclass : 'sortablehover',
  16. opacity: 0.8,
  17. fx: 200,
  18. axis: 'vertically',
  19. opacity: 0.4,
  20. revert: true,
  21. trim: 'art_',
  22. onchange:
  23. function(list){
  24. var arts = list[0].o[list[0].id];
  25. var vals = new Array();
  26. var a;
  27. for (a in arts) {
  28. vals[a] = arts[a].replace(/article./, '');
  29. }
  30. $('#id_article_order').attr('value', vals.join(','));
  31. }
  32. });
  33. }
  34. );
  35. </script>
  36. {% endblock %}
  37.  
  38. {% block after_related_objects %}
  39. {% if original.articles %}
  40. <style>
  41. .sortableitem {
  42. cursor:move;
  43. width: 300px;
  44. list-style-type: none;
  45. }
  46. </style>
  47.  
  48. <h4>Associated Articles</h4>
  49. <ol class="articles" id="article_list">
  50. {% for art in original.articles %}
  51. <li id="article.{{art.id}}" class="sortableitem">{{art.title}}</li>
  52.  
  53. {% endfor %}
  54. </ol>
  55. {% endif %}
  56. {% endblock %}
Add Comment
Please, Sign In to add comment