Improvements to user management
This commit is contained in:
+29
-4
@@ -56,11 +56,13 @@ class Examination(models.Model):
|
||||
|
||||
|
||||
class Site(models.Model):
|
||||
site = models.CharField(max_length=200)
|
||||
initials = models.CharField(max_length=200)
|
||||
"""Model to hold site details"""
|
||||
full_name = models.CharField(max_length=255, blank=True, help_text="Name of the site")
|
||||
short_code = models.CharField(max_length=255, blank=True, help_text="Shortcode/name of the site")
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.site
|
||||
return self.short_code
|
||||
|
||||
|
||||
class Condition(tagulous.models.TagModel):
|
||||
@@ -667,6 +669,7 @@ class UserProfile(models.Model):
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
supervisor_email = models.EmailField(blank=True)
|
||||
supervisor_name = models.CharField(max_length=100, blank=True)
|
||||
supervisor = models.ForeignKey("Supervisor", on_delete=models.SET_NULL, blank=True, null=True, related_name="trainee")
|
||||
registration_number = models.CharField(max_length=25, blank=True)
|
||||
grade = models.ForeignKey(UserGrades, null=True, blank=True, help_text="User grade", on_delete=models.CASCADE)
|
||||
peninsula_trainee = models.BooleanField(default=False)
|
||||
@@ -675,7 +678,28 @@ class UserProfile(models.Model):
|
||||
def getusername(self):
|
||||
return self.user.username
|
||||
|
||||
def __str__(self):
|
||||
return f"Userprofile {self.user}"
|
||||
|
||||
username = property(getusername)
|
||||
|
||||
class Supervisor(models.Model):
|
||||
"""Model to hold individual supervisor details (email and name)
|
||||
|
||||
This can be linked with a user account.
|
||||
"""
|
||||
email = models.EmailField(blank=True, unique=True, help_text="The (nhs.net) email address of the supervisor")
|
||||
name = models.CharField(max_length=255, blank=True, help_text="Name of the supervisor")
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True, help_text="If the supervisor has an account on the test system that can be associated here")
|
||||
site = models.ForeignKey("Site", on_delete=models.SET_NULL, null=True, blank=True)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} ({self.email})"
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('generic:supervisor_detail', kwargs={'pk': self.pk})
|
||||
|
||||
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
@@ -685,4 +709,5 @@ def create_user_profile(sender, instance, created, **kwargs):
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def save_user_profile(sender, instance, **kwargs):
|
||||
instance.userprofile.save()
|
||||
instance.userprofile.save()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user