From a37fedb9cc8b154c8b3acc7ff5c5d02742eab45b Mon Sep 17 00:00:00 2001 From: srbh001 <22B3905@iitb.ac.in> Date: Tue, 24 Oct 2023 15:29:09 +0530 Subject: [PATCH] (bans)Add : Extra field to bans model --- bans/models.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bans/models.py b/bans/models.py index 28fac391..48dc43ab 100644 --- a/bans/models.py +++ b/bans/models.py @@ -1,6 +1,8 @@ +from collections.abc import Iterable from django.db import models from uuid import uuid4 - +from users.models import UserProfile +from django.db.models.signals import post_save, post_delete, pre_save # Create your models here. @@ -25,7 +27,7 @@ class SSOBan(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, blank=False) banned_user = models.ForeignKey( - to="users.UserProfile", related_name="banned_user", on_delete=models.CASCADE + to="users.UserProfile", related_name="banned_user", on_delete=models.CASCADE, null=True, blank=True ) time_of_creation = models.DateTimeField(auto_now_add=True) reason = models.CharField(max_length=30, choices=BAN_REASON_CHOICHES) @@ -38,3 +40,12 @@ class SSOBan(models.Model): null=True, blank=True, ) + banned_user_ldapid = models.CharField(max_length=20, blank=True, null=True) + + + def save(self, *args, **kwargs) -> None: + if self.banned_user_ldapid: + self.banned_user = UserProfile.objects.get(ldap_id=self.banned_user_ldapid) + return super().save(*args, **kwargs) + +