我非常感谢有关如何构建以下模型的一些指导。我想确保我以理想的方式做到这一点。
我想跟踪一些有关我工作中员工的信息。基本上,过去的教育和过去的工作经验
所以这是我能想到的关系
- 教育
- 一个员工可以去过几所学校,每所学校可以有很多学生(m2m)
- 学生上学一段时间
- 一个学生可以从同一所学校获得多个学位,并且该学校提供多个学位 (m2m)
- 工作(几乎和教育一样)
- m2m 与员工和公司的关系
- 员工在公司工作到设定的时间
- 员工可以在一家公司从事多项工作 (m2m)
基本上遵循上面的内容,这是我制定的代码:
#make a list of numbers in a tuple
START_DATE_CHOICES = dict((str(x),str(x)) for x in range(date.today().year-30,date.today().year+1))
END_DATE_CHOICES = START_DATE_CHOICES
START_DATE_CHOICES = START_DATE_CHOICES.items()
START_DATE_CHOICES.sort()
START_DATE_CHOICES.reverse()
START_DATE_CHOICES = tuple(START_DATE_CHOICES)
END_DATE_CHOICES['current'] = 'current'
END_DATE_CHOICES = END_DATE_CHOICES.items()
END_DATE_CHOICES.sort()
END_DATE_CHOICES.reverse()
END_DATE_CHOICES = tuple(END_DATE_CHOICES)
#both schools and companies
class Institution(models.Model):
name = models.CharField(max_length = 75)
class Education(models.Model):
DEGREE_CHOICES = (
('A.A.', 'Associate'),
('Minor', 'Minor'),
('B.A.', 'Bachelor of Arts'),
('B.S.', 'Bachelor of Science'),
('Masters', 'Masters'),
('Ph. D.', 'Doctor of Philosophy'),
)
school = models.ManyToManyField(Institution, through='Dates')
degree = models.CharField(max_length = 5, choices = DEGREE_CHOICES, null = True)
subject = models.CharField(max_length = 20, null = True)
class Work(models.Model):
company = models.ManyToManyField(Institution, through='Dates')
position = models.CharField(max_length = 50, null = True)
jobDescription = models.TextField(null = True)
class Dates(models.Model):
education = models.ForeignKey(Education, null = True)
work = models.ForeignKey(Work, null = True)
institution = models.ForeignKey(Institution)
start = models.CharField(max_length = 4, choices = START_DATE_CHOICES)
end = models.CharField(max_length = 7, choices = END_DATE_CHOICES)
class Person(models.Model):
....
school = models.ManyToManyField(Institution, blank=True)
education = models.ManyToManyField(Education, blank = True)
company = models.ManyToManyField(Institution, blank = True, related_name="%(app_label)s_%(class)s_related")
work = models.ManyToManyField(Work, blank=True)
....
所以我的问题是:这是一种可以接受的方式吗?我是新手,我不确定我是否只是在滥用人际关系
另外,我敢肯定有一种更简单的方法来完成整个开始/结束日期的事情......虽然无法弄清楚
任何指点将不胜感激,谢谢!