~mhall119/summit/site-menu

« back to all changes in this revision

Viewing changes to summit/common/models.py

  • Committer: Chris Johnston
  • Date: 2012-03-08 02:35:38 UTC
  • mfrom: (309.1.1 site-menus)
  • Revision ID: chrisjohnston@ubuntu.com-20120308023538-lixle7u18behyxev
Adds working menu

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    def __unicode__(self):
17
17
        return "%s" % self.name
18
18
 
19
 
    def save(self, force_insert=False, force_update=False):
20
 
        """
21
 
        Re-order all items at from 10 upwards, at intervals of 10.
22
 
        This makes it easy to insert new items in the middle of 
23
 
        existing items without having to manually shuffle 
24
 
        them all around.
25
 
        """
26
 
        super(Menu, self).save(force_insert, force_update)
27
 
        
28
 
        current = 10
29
 
        for item in MenuItem.objects.filter(menu=self).order_by('order'):
30
 
            item.order = current
31
 
            item.save()
32
 
            current += 10
33
 
 
34
19
class MenuItem(models.Model):
35
20
    menu = models.ForeignKey(Menu)
36
21
    order = models.IntegerField()