Skip to content

Commit

Permalink
Merge pull request #1691 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
org college add
  • Loading branch information
adnankattekaden authored Dec 2, 2023
2 parents 9146cc3 + 984e664 commit 2f21f40
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
8 changes: 7 additions & 1 deletion api/dashboard/affiliation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
class AffiliationListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
organization_count = serializers.SerializerMethodField()

class Meta:
model = OrgAffiliation
fields = "__all__"
fields = ['id','title','organization_count', 'created_by', 'updated_by']

def get_organization_count(self,obj):
return obj.organizations.count()



class AffiliationCUDSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
7 changes: 5 additions & 2 deletions api/dashboard/organisation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Department,
OrgKarmaType,
OrgKarmaLog,
College
)
from utils.permission import JWTUtils
from utils.types import OrganizationType
Expand Down Expand Up @@ -114,8 +115,10 @@ def create(self, validated_data):
validated_data["id"] = str(uuid.uuid4())
validated_data["created_by_id"] = user_id
validated_data["updated_by_id"] = user_id

return Organization.objects.create(**validated_data)
orgobj = Organization.objects.create(**validated_data)
if validated_data.get("org_type") == OrganizationType.COLLEGE.value:
College.objects.create(org = orgobj, created_by_id=user_id, updated_by_id = user_id )
return orgobj

def update(self, instance, validated_data):
user_id = self.context.get("user_id")
Expand Down
4 changes: 2 additions & 2 deletions db/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Organization(models.Model):
title = models.CharField(max_length=100)
code = models.CharField(unique=True, max_length=12)
org_type = models.CharField(max_length=25)
affiliation = models.ForeignKey(OrgAffiliation, on_delete=models.CASCADE, blank=True, null=True)
affiliation = models.ForeignKey(OrgAffiliation, on_delete=models.CASCADE, blank=True, null=True, related_name='organization_affiliation')
district = models.ForeignKey(District, on_delete=models.CASCADE, related_name='organization_district')
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='organization_updated_by')
Expand Down Expand Up @@ -122,7 +122,7 @@ class Meta:

class College(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4())
level = models.IntegerField()
level = models.IntegerField(default=1)
org = models.OneToOneField(Organization, on_delete=models.CASCADE, related_name='college_org', unique=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='college_updated_by')
Expand Down
2 changes: 1 addition & 1 deletion mulearnbackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.common.CommonMiddleware",
"corsheaders.middleware.CorsMiddleware",
# "mulearnbackend.middlewares.UniversalErrorHandlerMiddleware",
"mulearnbackend.middlewares.UniversalErrorHandlerMiddleware",
]

ROOT_URLCONF = "mulearnbackend.urls"
Expand Down

0 comments on commit 2f21f40

Please sign in to comment.