La til medlemsfunksjoner i Placement-klassen.
This commit is contained in:
parent
eaa2f211de
commit
232d53380a
|
@ -206,3 +206,35 @@ class Placement(models.Model):
|
|||
|
||||
def __unicode__(self):
|
||||
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)
|
||||
|
||||
|
||||
|
|
Reference in New Issue