Нет описания

models.py 1.2KB

123456789101112131415161718192021222324252627282930
  1. from django.db import models
  2. # Create your models here.
  3. from django.contrib.auth.models import User
  4. class UserProfile(models.Model):
  5. POSITION_CHOICES = [
  6. ('QA_STAFF', 'QA Staff'),
  7. ('QA_MANAGER', 'QA. MG.'),
  8. ('QA_AST_MANAGER', 'QA. Asst. MG.'),
  9. ('QA_ENGINEER', 'QA. Engineer'),
  10. ]
  11. user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
  12. bio = models.TextField(blank=True, null=True)
  13. profile_picture = models.ImageField(upload_to="profile/%Y/%m/%d/", blank=True, null=True)
  14. signed_picture = models.ImageField(upload_to="signed/%Y/%m/%d/", blank=True, null=True)
  15. email = models.EmailField(blank=True, null=True) # New email field
  16. position = models.CharField(max_length=20, choices=POSITION_CHOICES, blank=True, null=True) # New position field
  17. qa2_default = models.BooleanField(default=False)
  18. def save(self, *args, **kwargs):
  19. if self.qa2_default:
  20. UserProfile.objects.exclude(pk=self.pk).filter(qa2_default=True).update(qa2_default=False)
  21. super().save(*args, **kwargs)
  22. def __str__(self):
  23. pos = self.get_position_display()
  24. return f"{self.user.username} / {self.user.first_name} {self.user.last_name} #{pos}"