Skip to content

Commit

Permalink
Merge pull request #587 from bharath637462/developer_bharath
Browse files Browse the repository at this point in the history
model field redundancy removed
  • Loading branch information
andrewtavis authored Nov 29, 2023
2 parents 31a2cf8 + ea474ba commit ad6ad64
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 90 deletions.
20 changes: 8 additions & 12 deletions backend/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
- UserTopic
"""

import uuid

from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import ArrayField
from django.db import models

from backend.mixins.models import BaseModelMixin, ModelMixin


class SupportEntityType(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class SupportEntityType(BaseModelMixin):
name = models.CharField(max_length=255)

def __str__(self) -> str:
return self.name


class Support(models.Model):
class Support(BaseModelMixin):
supporter_type = models.ForeignKey(
"SupportEntityType", on_delete=models.CASCADE, related_name="supporter"
)
Expand All @@ -41,8 +40,7 @@ def __str__(self) -> str:
return str(self.id)


class User(AbstractUser):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class User(AbstractUser, ModelMixin):
user_name = models.CharField(max_length=255)
name = models.CharField(max_length=255)
password = models.CharField(max_length=255)
Expand All @@ -57,30 +55,28 @@ class User(AbstractUser):
private = models.BooleanField(default=False)
high_risk = models.BooleanField(default=False)
total_flags = models.IntegerField(default=0)
creation_date = models.DateTimeField(auto_now_add=True)
deletion_date = models.DateField(null=True)

def __str__(self) -> str:
return self.username


class UserResource(models.Model):
class UserResource(BaseModelMixin):
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
resource_id = models.ForeignKey("content.Resource", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class UserTask(models.Model):
class UserTask(BaseModelMixin):
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
task_id = models.ForeignKey("content.Task", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class UserTopic(models.Model):
class UserTopic(BaseModelMixin):
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
topic_id = models.ForeignKey("content.Topic", on_delete=models.CASCADE)

Expand Down
37 changes: 37 additions & 0 deletions backend/backend/mixins/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import uuid

from django.db import models
from django.utils.translation import gettext_lazy as _


class BaseModelMixin(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
active = models.BooleanField(default=True)

class Meta:
abstract = True


class ModelMixin(BaseModelMixin):
created_by = models.ForeignKey(
"authentication.User",
verbose_name=_("Created by"),
on_delete=models.SET_NULL,
editable=False,
null=True,
related_name="created_%(class)s_set",
)
modified_by = models.ForeignKey(
"authentication.User",
verbose_name=_("Modified by"),
on_delete=models.SET_NULL,
editable=False,
null=True,
related_name="modified_%(class)s_set",
)
created_at = models.DateTimeField(_("Created at"), auto_now_add=True)
modified_at = models.DateTimeField(_("Modified at"), auto_now=True)
deleted_at = models.DateField(_("Deleted at"), null=True, blank=True)

class Meta:
abstract = True
2 changes: 1 addition & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"DEFAULT_THROTTLE_RATES": {"anon": "7/min", "user": "10/min"},
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
'DEFAULT_PAGINATION_ORDERS_OBJECTS': False,
"DEFAULT_PAGINATION_ORDERS_OBJECTS": False,
"PAGE_SIZE": 20,
}

Expand Down
22 changes: 7 additions & 15 deletions backend/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
- TopicFormat
"""

import uuid

from django.contrib.postgres.fields import ArrayField
from django.db import models

from backend.mixins.models import BaseModelMixin, ModelMixin


class Resource(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Resource(ModelMixin):
name = models.CharField(max_length=255)
description = models.TextField(max_length=500)
topics = ArrayField(models.CharField(max_length=255))
Expand All @@ -34,41 +33,34 @@ def __str__(self) -> str:
return self.name


class Task(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Task(ModelMixin):
name = models.CharField(max_length=255)
description = models.TextField(max_length=500)
location = models.CharField(max_length=255)
tags = ArrayField(models.CharField(max_length=255))
creation_date = models.DateTimeField(auto_now_add=True)
deletion_date = models.DateField(null=True)

def __str__(self) -> str:
return self.name


class Topic(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Topic(ModelMixin):
name = models.CharField(max_length=255)
active = models.BooleanField(default=True)
description = models.TextField(max_length=500)
creation_date = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
deprecation_date = models.DateField(null=True)

def __str__(self) -> str:
return self.name


class ResourceTopic(models.Model):
class ResourceTopic(BaseModelMixin):
resource_id = models.ForeignKey(Resource, on_delete=models.CASCADE)
topic_id = models.ForeignKey("Topic", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class TopicFormat(models.Model):
class TopicFormat(BaseModelMixin):
topic_id = models.ForeignKey(Topic, on_delete=models.CASCADE)
format_id = models.ForeignKey("events.Format", on_delete=models.CASCADE)

Expand Down
45 changes: 16 additions & 29 deletions backend/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
- GroupTopic
"""

import uuid

from django.contrib.postgres.fields import ArrayField
from django.db import models

from backend.mixins.models import BaseModelMixin, ModelMixin


class Organization(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Organization(ModelMixin):
name = models.CharField(max_length=255)
tagline = models.CharField(max_length=255)
location = models.CharField(max_length=255)
Expand All @@ -38,49 +37,41 @@ class Organization(models.Model):
topics = ArrayField(models.CharField(max_length=255))
social_accounts = ArrayField(models.CharField(max_length=255))
total_flags = models.IntegerField(null=True)
created_by = models.ForeignKey(
"authentication.User", related_name="created_orgs", on_delete=models.CASCADE
)
high_risk = models.BooleanField(default=False)
creation_date = models.DateTimeField(auto_now_add=True)
deletion_date = models.DateField(null=True)

def __str__(self) -> str:
return self.name


class OrganizationApplicationStatus(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class OrganizationApplicationStatus(BaseModelMixin):
status_name = models.CharField(max_length=255)

def __str__(self) -> str:
return self.status_name


class OrganizationApplication(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class OrganizationApplication(ModelMixin):
org_id = models.IntegerField(null=True)
status = models.ForeignKey(
"OrganizationApplicationStatus", on_delete=models.CASCADE
)
orgs_in_favor = ArrayField(models.IntegerField(null=True, blank=True), blank=True)
orgs_against = ArrayField(models.IntegerField(null=True, blank=True), blank=True)
creation_date = models.DateTimeField(auto_now_add=True)
status_updated = models.DateTimeField(auto_now=True)

def __str__(self) -> str:
return str(self.creation_date)
return str(self.created_at)


class OrganizationEvent(models.Model):
class OrganizationEvent(BaseModelMixin):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
event_id = models.ForeignKey("events.Event", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class OrganizationMember(models.Model):
class OrganizationMember(BaseModelMixin):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
user_id = models.ForeignKey("authentication.User", on_delete=models.CASCADE)
is_owner = models.BooleanField(default=False)
Expand All @@ -91,31 +82,27 @@ def __str__(self) -> str:
return str(self.id)


class OrganizationResource(models.Model):
class OrganizationResource(BaseModelMixin):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
resource_id = models.ForeignKey("content.Resource", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class Group(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Group(ModelMixin):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
tagline = models.CharField(max_length=255)
description = models.TextField(max_length=500)
social_accounts = ArrayField(models.CharField(max_length=255))
total_flags = models.IntegerField(null=True)
created_by = models.ForeignKey("authentication.User", on_delete=models.CASCADE)
creation_date = models.DateTimeField(auto_now_add=True)
deletion_date = models.DateField(null=True)

def __str__(self) -> str:
return self.name


class OrganizationTask(models.Model):
class OrganizationTask(BaseModelMixin):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
task_id = models.ForeignKey("content.Task", on_delete=models.CASCADE)
group_id = models.ForeignKey("Group", on_delete=models.CASCADE)
Expand All @@ -124,23 +111,23 @@ def __str__(self) -> str:
return str(self.id)


class OrganizationTopic(models.Model):
class OrganizationTopic(BaseModelMixin):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
topic_id = models.ForeignKey("content.Topic", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class GroupEvent(models.Model):
class GroupEvent(BaseModelMixin):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
event_id = models.ForeignKey("events.Event", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class GroupMember(models.Model):
class GroupMember(BaseModelMixin):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
user_id = models.ForeignKey("authentication.User", on_delete=models.CASCADE)
is_admin = models.BooleanField(default=False)
Expand All @@ -149,15 +136,15 @@ def __str__(self) -> str:
return str(self.id)


class GroupResource(models.Model):
class GroupResource(BaseModelMixin):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
resource_id = models.ForeignKey("content.Resource", on_delete=models.CASCADE)

def __str__(self) -> str:
return str(self.id)


class GroupTopic(models.Model):
class GroupTopic(BaseModelMixin):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
topic_id = models.ForeignKey("content.Topic", on_delete=models.CASCADE)

Expand Down
Loading

0 comments on commit ad6ad64

Please sign in to comment.