Created
February 13, 2013 13:37
-
-
Save jjangdm/4944655 to your computer and use it in GitHub Desktop.
model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from django.db import models | |
import datetime | |
today = datetime.datetime.now() | |
class Category(models.Model): | |
categoryNumber = models.CharField(max_length=3, verbose_name="항목번호") | |
item = models.CharField(max_length=40, verbose_name="항목") | |
description = models.TextField(blank=True, verbose_name="메모") | |
def __unicode__(self): | |
return self.item | |
class Meta: | |
ordering = ["categoryNumber","item"] | |
verbose_name = "항목" | |
verbose_name_plural = "항목" | |
class Member(models.Model): | |
name = models.CharField(max_length=10, verbose_name="이름") | |
birthday = models.DateField(verbose_name="생일",) | |
phone = models.CharField(max_length=11, verbose_name="전화번호", help_text="'-'기호 빼고 입력") | |
email = models.EmailField(verbose_name="Email",blank=True) | |
address = models.CharField(max_length=100, verbose_name="주소", blank=True) | |
homepage = models.URLField(blank=True, verbose_name="홈페이지") | |
family = models.ManyToManyField("self", blank=True, verbose_name="가족") | |
def get_family(self): | |
return (",").join(self.family.all().values_list("name", flat=True)) | |
comment = models.TextField(blank=True, verbose_name="비고") | |
def __unicode__(self): | |
return self.name | |
class Meta: | |
ordering = ['name'] | |
verbose_name = "회원" | |
verbose_name_plural = "회원" | |
class Budget(models.Model): | |
fiscalYear = models.CharField(max_length=4, verbose_name="회계년도", default=today.year) | |
item = models.ForeignKey(Category, verbose_name="항목") | |
money = models.IntegerField(verbose_name="금액",) | |
delta = models.FloatField(verbose_name="전년결산대비(%)",) | |
comment = models.TextField(blank=True, verbose_name="비고") | |
def __unicode__(self): | |
return self.item.item | |
class Meta: | |
ordering = ["fiscalYear","item"] | |
verbose_name = "예산" | |
verbose_name_plural = "예산" | |
class Income(models.Model): | |
date = models.DateField(default=today.date, verbose_name="날짜") | |
category = models.ForeignKey(Category, verbose_name="항목") | |
name = models.ForeignKey(Member, verbose_name="이름") | |
money = models.IntegerField(verbose_name="금액",) | |
comment = models.TextField(blank=True, verbose_name="비고") | |
week = models.IntegerField(blank=True, verbose_name="주차", editable=False) | |
def save(self, *args, **kwargs): | |
if not self.week: | |
self.week = self.date.isocalendar()[1] | |
return super(Income, self).save(*args, **kwargs) | |
def __unicode__(self): | |
return self.name.name | |
class Meta: | |
ordering = ["-date","category"] | |
verbose_name = "수입" | |
verbose_name_plural = "수입" | |
class Outcome(models.Model): | |
date = models.DateField(default=today.date, verbose_name="날짜") | |
category = models.ForeignKey(Category, verbose_name="항목") | |
executor = models.CharField(max_length=10, verbose_name="이름", default="담당자") | |
money = models.IntegerField(verbose_name="금액",) | |
comment = models.TextField(blank=True, verbose_name="비고") | |
week = models.IntegerField(blank=True, verbose_name="주차", editable=False) | |
def save(self, *args, **kwargs): | |
if not self.week: | |
self.week = self.date.isocalendar()[1] | |
return super(Outcome, self).save(*args, **kwargs) | |
def __unicode__(self): | |
return self.category.item | |
class Meta: | |
ordering = ["-date","category"] | |
verbose_name = "지출" | |
verbose_name_plural = "지출" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment