models.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. # Create your models here.
  4. from mptt.models import MPTTModel
  5. #部门表
  6. class Dapt(MPTTModel):
  7. name = models.CharField(max_length=50)
  8. parent = models.ForeignKey('self', verbose_name='上级部门', null=True, blank=True, related_name='pid',
  9. on_delete=models.CASCADE)
  10. def setObject(self, data):
  11. for key, val in data.items():
  12. if hasattr(self, key):
  13. self.__setattr__(key, val)
  14. return self
  15. #岗位
  16. class Post(models.Model):
  17. name = models.CharField(max_length=50)
  18. #部门岗位关联表
  19. class DaptPost(models.Model):
  20. dapt = models.ForeignKey('Dapt', verbose_name='部门', null=False, blank=False, related_name='dp_dapt', on_delete=models.CASCADE)
  21. post = models.ForeignKey('Post', verbose_name='岗位', null=False, blank=False, related_name='dp_post', on_delete=models.CASCADE)
  22. class Meta:
  23. unique_together = ('dapt', 'post')
  24. #部门人员关联表
  25. class DaptUser(models.Model):
  26. dapt = models.ForeignKey('Dapt', verbose_name='部门', null=False, blank=False, related_name='du_dapt', on_delete=models.CASCADE)
  27. user = models.ForeignKey(User, verbose_name='人员', null=False, blank=False, related_name='du_user', on_delete=models.CASCADE)
  28. def setObject(self, data):
  29. for key, val in data.items():
  30. if hasattr(self, key):
  31. self.__setattr__(key, val)
  32. return self
  33. class Meta:
  34. unique_together = ('dapt', 'user')
  35. #岗位人员关联表
  36. class PostUser(models.Model):
  37. post = models.ForeignKey('Post', verbose_name='岗位', null=False, blank=False, related_name='pu_post', on_delete=models.CASCADE)
  38. user = models.ForeignKey(User, verbose_name='人员', null=False, blank=False, related_name='pu_user', on_delete=models.CASCADE)
  39. class Meta:
  40. unique_together = ('post', 'user')