1 | from django.db import models
|
---|
2 |
|
---|
3 | # Create your models here.
|
---|
4 | class Employee(models.Model):
|
---|
5 | name = models.CharField(max_length=20, unique=True)
|
---|
6 |
|
---|
7 | def __str__(self):
|
---|
8 | return self.name
|
---|
9 |
|
---|
10 | def current_title(self):
|
---|
11 | return self.employeetitle_set.latest('start_date')
|
---|
12 | current_title.admin_order_field = 'employeetitle__title__name'
|
---|
13 |
|
---|
14 | class EmployeeTitle(models.Model):
|
---|
15 | employee = models.ForeignKey('Employee')
|
---|
16 | title = models.ForeignKey('Title')
|
---|
17 | start_date = models.DateField()
|
---|
18 | end_date = models.DateField(null=True, blank=True)
|
---|
19 |
|
---|
20 | def __str__(self):
|
---|
21 | return self.title.name
|
---|
22 |
|
---|
23 | class Title(models.Model):
|
---|
24 | name = models.CharField(max_length=20, unique=True)
|
---|
25 |
|
---|
26 | def __str__(self):
|
---|
27 | return self.name
|
---|