track history using simple django history

This commit is contained in:
karthik murakonda 2022-05-29 00:50:32 +05:30
parent 44ee9f466e
commit f2458f21cb
4 changed files with 19 additions and 9 deletions

1
.gitignore vendored
View File

@ -139,3 +139,4 @@ dmypy.json
/CDC_Backend/Storage/ /CDC_Backend/Storage/
.idea .idea
*.pyc *.pyc
dev.env

View File

@ -1,4 +1,5 @@
from django.contrib import admin from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from django.contrib.admin.templatetags.admin_urls import admin_urlname from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.utils.html import format_html from django.utils.html import format_html
@ -6,8 +7,8 @@ from django.utils.safestring import SafeText
from .models import * from .models import *
admin.site.register(User) admin.site.register(User, SimpleHistoryAdmin)
admin.site.register(Admin) admin.site.register(Admin, SimpleHistoryAdmin)
admin.site.site_header = "CDC Recruitment Portal" admin.site.site_header = "CDC Recruitment Portal"
@ -18,7 +19,7 @@ def model_admin_url(obj, name=None) -> str:
@admin.register(Student) @admin.register(Student)
class Student(admin.ModelAdmin): class Student(SimpleHistoryAdmin):
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply') list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
search_fields = ("roll_no", "name", "phone_number") search_fields = ("roll_no", "name", "phone_number")
ordering = ("roll_no", "name", "batch", "branch", "phone_number") ordering = ("roll_no", "name", "batch", "branch", "phone_number")
@ -37,7 +38,7 @@ class Student(admin.ModelAdmin):
@admin.register(Placement) @admin.register(Placement)
class Placement(admin.ModelAdmin): class Placement(SimpleHistoryAdmin):
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC') list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME) search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC') ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
@ -45,7 +46,7 @@ class Placement(admin.ModelAdmin):
@admin.register(PlacementApplication) @admin.register(PlacementApplication)
class PlacementApplication(admin.ModelAdmin): class PlacementApplication(SimpleHistoryAdmin):
list_display = ('id', 'Placement', 'Student', 'selected') list_display = ('id', 'Placement', 'Student', 'selected')
search_fields = ('id',) search_fields = ('id',)
ordering = ('id',) ordering = ('id',)
@ -59,7 +60,7 @@ class PlacementApplication(admin.ModelAdmin):
@admin.register(PrePlacementOffer) @admin.register(PrePlacementOffer)
class PrePlacementOffer(admin.ModelAdmin): class PrePlacementOffer(SimpleHistoryAdmin):
list_display = ('company', 'Student', 'accepted') list_display = ('company', 'Student', 'accepted')
search_fields = ('company',) search_fields = ('company',)
ordering = ('company',) ordering = ('company',)

View File

@ -1,6 +1,7 @@
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from simple_history.models import HistoricalRecords
from .constants import * from .constants import *
@ -13,6 +14,7 @@ class User(models.Model):
id = models.CharField(blank=False, max_length=25) id = models.CharField(blank=False, max_length=25)
user_type = ArrayField(models.CharField(blank=False, max_length=10), size=4, default=list, blank=False) user_type = ArrayField(models.CharField(blank=False, max_length=10), size=4, default=list, blank=False)
last_login_time = models.DateTimeField(default=timezone.now) last_login_time = models.DateTimeField(default=timezone.now)
history = HistoricalRecords()
class Meta: class Meta:
verbose_name_plural = "User" verbose_name_plural = "User"
@ -30,6 +32,7 @@ class Student(models.Model):
default=list, blank=True) default=list, blank=True)
cpi = models.DecimalField(decimal_places=2, max_digits=4) cpi = models.DecimalField(decimal_places=2, max_digits=4)
can_apply = models.BooleanField(default=True, verbose_name='Registered') can_apply = models.BooleanField(default=True, verbose_name='Registered')
history = HistoricalRecords()
def __str__(self): def __str__(self):
return str(self.roll_no) return str(self.roll_no)
@ -38,6 +41,7 @@ class Student(models.Model):
class Admin(models.Model): class Admin(models.Model):
id = models.CharField(blank=False, max_length=15, primary_key=True) id = models.CharField(blank=False, max_length=15, primary_key=True)
name = models.CharField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT) name = models.CharField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT)
history = HistoricalRecords()
def two_day_after_today(): def two_day_after_today():
@ -114,6 +118,7 @@ class Placement(models.Model):
deadline_datetime = models.DateTimeField(blank=False, verbose_name="Deadline Date", default=two_day_after_today) deadline_datetime = models.DateTimeField(blank=False, verbose_name="Deadline Date", default=two_day_after_today)
created_at = models.DateTimeField(blank=False, default=None, null=True) created_at = models.DateTimeField(blank=False, default=None, null=True)
updated_at = models.DateTimeField(blank=False, default=None, null=True) updated_at = models.DateTimeField(blank=False, default=None, null=True)
history = HistoricalRecords()
def format(self): def format(self):
if self.company_name is not None: if self.company_name is not None:
@ -179,6 +184,7 @@ class PlacementApplication(models.Model):
selected = models.BooleanField(null=True, default=None, blank=True) selected = models.BooleanField(null=True, default=None, blank=True)
applied_at = models.DateTimeField(blank=False, default=None, null=True) applied_at = models.DateTimeField(blank=False, default=None, null=True)
updated_at = models.DateTimeField(blank=False, default=None, null=True) updated_at = models.DateTimeField(blank=False, default=None, null=True)
history = HistoricalRecords()
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
''' On save, add timestamps ''' ''' On save, add timestamps '''
@ -206,3 +212,4 @@ class PrePlacementOffer(models.Model):
tier = models.CharField(blank=False, choices=TIERS, max_length=10) tier = models.CharField(blank=False, choices=TIERS, max_length=10)
designation = models.CharField(blank=False, max_length=25, default=None, null=True) designation = models.CharField(blank=False, max_length=25, default=None, null=True)
accepted = models.BooleanField(default=None, null=True) accepted = models.BooleanField(default=None, null=True)
history = HistoricalRecords()

View File

@ -29,7 +29,7 @@ SECRET_KEY = 'e_i2g3z!y4+p3dwm%k9k=zmsot@aya-0$mmetgxz4mp#8_oy#*'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['cdc-iitdh.herokuapp.com/', 'localhost', '192.168.29.199'] ALLOWED_HOSTS = ['cdc-iitdh.herokuapp.com/', 'localhost', '192.168.29.199', '127.0.0.1']
# Application definition # Application definition
@ -44,7 +44,8 @@ INSTALLED_APPS = [
'rest_framework', 'rest_framework',
'corsheaders', 'corsheaders',
'django_db_logger', 'django_db_logger',
'background_task' 'background_task',
'simple_history',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -57,7 +58,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
] ]
ROOT_URLCONF = 'CDC_Backend.urls' ROOT_URLCONF = 'CDC_Backend.urls'