Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

La til medlemsfunksjoner i Placement-klassen.

This commit is contained in:
Øyvind Bergland Leknes 2011-03-05 22:20:08 +00:00
parent eaa2f211de
commit 232d53380a
1 changed files with 32 additions and 0 deletions

View File

@ -206,3 +206,35 @@ class Placement(models.Model):
def __unicode__(self): def __unicode__(self):
return self.category.name+" at "+self.shelf return self.category.name+" at "+self.shelf
def as_list(self):
shelf = self.shelf
return [self.category, shelf[0], int(shelf[1]), int(shelf[2])]
def get_shelf(self):
return self.shelf[0]
def get_row(self):
return int(self.shelf[2])
def get_column(self):
return int(self.shelf[1])
@staticmethod
def shelf_as_list(shelfname):
placements = Placement.objects.filter(shelf__startswith=shelfname)
rows = max(map(lambda x: x.get_row(), placements))
columns = max(map(lambda x: x.get_column(), placements))
shelf_list = [ [[] for i in xrange(rows+1)] for j in xrange(columns+1)]
for placement in placements:
shelf_list[placement.get_column()][placement.get_row()].append(placement.category)
return shelf_list
@staticmethod
def get_all_shelves():
shelves = set()
for item in Placement.objects.all():
shelves.add(item.get_shelf())
return list(shelves)