models.py 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.db import models
  2. from django.utils.encoding import python_2_unicode_compatible
  3. GENDER_CHOICES = (
  4. ('M', 'Male'),
  5. ('F', 'Female'),
  6. )
  7. class Account(models.Model):
  8. num = models.IntegerField()
  9. @python_2_unicode_compatible
  10. class Person(models.Model):
  11. name = models.CharField(max_length=20)
  12. gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
  13. pid = models.IntegerField(null=True, default=None)
  14. def __str__(self):
  15. return self.name
  16. class Employee(Person):
  17. employee_num = models.IntegerField(default=0)
  18. profile = models.ForeignKey('Profile', models.SET_NULL, related_name='profiles', null=True)
  19. accounts = models.ManyToManyField('Account', related_name='employees', blank=True)
  20. @python_2_unicode_compatible
  21. class Profile(models.Model):
  22. name = models.CharField(max_length=200)
  23. salary = models.FloatField(default=1000.0)
  24. def __str__(self):
  25. return self.name
  26. class ProxyEmployee(Employee):
  27. class Meta:
  28. proxy = True