2014-12-10 8 views
1

내가 몇 년 동안 직원의 근무 시간 매주 저장하는 온라인 출석 시스템에 대한 장고 응용 프로그램을 만드는 오전 (5 또는 6)모델은 특정 연도, 월, 주

에 대한 직원의 근무 시간을 저장합니다

employeeid, 년, 월, 주 및 시간이있는 테이블을 만들고 싶습니다. (예 : ID 200의 직원이 2015 년 1 월 1 일에 주 4 시간)

모델을 만들려고했습니다 (년, 월, 주, 기록) ManyToManyFields 및 Foreignkey Fields는 거의 없었지만 years과 employeeid, employeeid 및 month, years and month를 연결하는 테이블을 만들었지 만 employeeid, week, month 및 year 필드가있는 테이블은 만들지 않았습니다.

아무도 나에게이 필드에 대한 데이터베이스를 만들기 위해 모델에서 사용되는 관계를 말할 수 있습니까? , 당신은 기본 키를 만들 필요가 없습니다 (ID) 필드 :이 모델은 사용자의 요구 사항

주를 만족

from django.db import models 

class Month(models.Model): 
    id = models.IntegerField(primary_key = True, null = False) 
    weeks = models.ManyToManyField(Week, null = True) 

class Year(models.Model): 
    id = models.IntegerField(primary_key = True, null = False) 
    month = models.ManyToManyField(Month, null = True) 



class UserId(models.Model): 
    id = models.IntegerField(primary_key = True, null = False) 
    name = models.CharField(max_length = 56) // employee name 
    year = models.ForeignKey(Year, null = True) 



class Week(models.Model): 
    id = models.IntegerField(primary_key =True, null = False) 
    working_hours = models.IntegerField(null = True, default = 0) 


class Record(models.Model): 
    id = models.IntegerField(primary_key = True, null = False) 
    month = models.ManyToManyField(Month, null = True) 
    year = models.ManyToManyField(Year, null = True) 
    week = models.ManyToManyField(Week, null=True) 
    userid = models.ForeignKey(UserId, null = True)         

답변

1

- 여기

사전

에서 고맙습니다 내 Models.py입니다 그것은 자동으로 장고에 의해 만들어집니다.

from django.db import models 


class Employee(models.Model): 
    name = models.CharField(max_length = 56) 


class Record(models.Model): 
    employee = models.ForeignKey(Employee) 
    month = models.IntegerField() 
    year = models.IntegerField() 
    week = models.IntegerField() 
    hours = models.IntegerField() 

    class Meta: 
     unique_together = (('employee', 'month', 'year', 'week'),)