Skip to content

Instantly share code, notes, and snippets.

@jjangdm
Created March 10, 2013 11:37
Show Gist options
  • Save jjangdm/5128250 to your computer and use it in GitHub Desktop.
Save jjangdm/5128250 to your computer and use it in GitHub Desktop.
class Item(models.Model):
item_number = models.CharField(u"항목번호", max_length=3)
category = models.ForeignKey(Category, verbose_name=u"범주")
title = models.CharField(max_length=50, verbose_name=u"항목명")
slug = models.SlugField(blank=True)
description = models.TextField(blank=True, verbose_name=u'메모')
class Meta:
ordering = ["item_number"]
verbose_name = u'항목'
verbose_name_plural = u'항목'
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Item, self).save(*args, **kwargs)
def __unicode__(self):
return "%s - %s" % (self.category.title, self.title)
def sum_income(self):
item_list = Budget.objects.filter(item__item_number__startswith="00").values_list("money",flat=True)
return sum(item_list)
def sum_management(self):
item_list = Budget.objects.filter(item__item_number__startswith="11").values_list("money",flat=True)
return sum(item_list)
def sum_education(self):
item_list = Budget.objects.filter(item__item_number__startswith="12").values_list("money",flat=True)
return sum(item_list)
def sum_feed(self):
item_list = Budget.objects.filter(item__item_number__startswith="13").values_list("money",flat=True)
return sum(item_list)
def sum_reward(self):
item_list = Budget.objects.filter(item__item_number__startswith="14").values_list("money",flat=True)
return sum(item_list)
def sum_mission(self):
item_list = Budget.objects.filter(item__item_number__startswith="15").values_list("money",flat=True)
return sum(item_list)
def sum_operation(self):
item_list = Budget.objects.filter(item__item_number__startswith="16").values_list("money",flat=True)
return sum(item_list)
def sum_etc(self):
item_list = Budget.objects.filter(item__item_number__startswith="19").values_list("money",flat=True)
return sum(item_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment