track history using simple django history
This commit is contained in:
parent
44ee9f466e
commit
f2458f21cb
|
@ -139,3 +139,4 @@ dmypy.json
|
|||
/CDC_Backend/Storage/
|
||||
.idea
|
||||
*.pyc
|
||||
dev.env
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from simple_history.admin import SimpleHistoryAdmin
|
||||
from django.contrib.admin.templatetags.admin_urls import admin_urlname
|
||||
from django.shortcuts import resolve_url
|
||||
from django.utils.html import format_html
|
||||
|
@ -6,8 +7,8 @@ from django.utils.safestring import SafeText
|
|||
|
||||
from .models import *
|
||||
|
||||
admin.site.register(User)
|
||||
admin.site.register(Admin)
|
||||
admin.site.register(User, SimpleHistoryAdmin)
|
||||
admin.site.register(Admin, SimpleHistoryAdmin)
|
||||
|
||||
admin.site.site_header = "CDC Recruitment Portal"
|
||||
|
||||
|
@ -18,7 +19,7 @@ def model_admin_url(obj, name=None) -> str:
|
|||
|
||||
|
||||
@admin.register(Student)
|
||||
class Student(admin.ModelAdmin):
|
||||
class Student(SimpleHistoryAdmin):
|
||||
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
|
||||
search_fields = ("roll_no", "name", "phone_number")
|
||||
ordering = ("roll_no", "name", "batch", "branch", "phone_number")
|
||||
|
@ -37,7 +38,7 @@ class Student(admin.ModelAdmin):
|
|||
|
||||
|
||||
@admin.register(Placement)
|
||||
class Placement(admin.ModelAdmin):
|
||||
class Placement(SimpleHistoryAdmin):
|
||||
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
|
||||
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
|
||||
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
|
||||
|
@ -45,7 +46,7 @@ class Placement(admin.ModelAdmin):
|
|||
|
||||
|
||||
@admin.register(PlacementApplication)
|
||||
class PlacementApplication(admin.ModelAdmin):
|
||||
class PlacementApplication(SimpleHistoryAdmin):
|
||||
list_display = ('id', 'Placement', 'Student', 'selected')
|
||||
search_fields = ('id',)
|
||||
ordering = ('id',)
|
||||
|
@ -59,7 +60,7 @@ class PlacementApplication(admin.ModelAdmin):
|
|||
|
||||
|
||||
@admin.register(PrePlacementOffer)
|
||||
class PrePlacementOffer(admin.ModelAdmin):
|
||||
class PrePlacementOffer(SimpleHistoryAdmin):
|
||||
list_display = ('company', 'Student', 'accepted')
|
||||
search_fields = ('company',)
|
||||
ordering = ('company',)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
from .constants import *
|
||||
|
||||
|
@ -13,6 +14,7 @@ class User(models.Model):
|
|||
id = models.CharField(blank=False, max_length=25)
|
||||
user_type = ArrayField(models.CharField(blank=False, max_length=10), size=4, default=list, blank=False)
|
||||
last_login_time = models.DateTimeField(default=timezone.now)
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "User"
|
||||
|
@ -30,6 +32,7 @@ class Student(models.Model):
|
|||
default=list, blank=True)
|
||||
cpi = models.DecimalField(decimal_places=2, max_digits=4)
|
||||
can_apply = models.BooleanField(default=True, verbose_name='Registered')
|
||||
history = HistoricalRecords()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.roll_no)
|
||||
|
@ -38,6 +41,7 @@ class Student(models.Model):
|
|||
class Admin(models.Model):
|
||||
id = models.CharField(blank=False, max_length=15, primary_key=True)
|
||||
name = models.CharField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT)
|
||||
history = HistoricalRecords()
|
||||
|
||||
|
||||
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)
|
||||
created_at = models.DateTimeField(blank=False, default=None, null=True)
|
||||
updated_at = models.DateTimeField(blank=False, default=None, null=True)
|
||||
history = HistoricalRecords()
|
||||
|
||||
def format(self):
|
||||
if self.company_name is not None:
|
||||
|
@ -179,6 +184,7 @@ class PlacementApplication(models.Model):
|
|||
selected = models.BooleanField(null=True, default=None, blank=True)
|
||||
applied_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):
|
||||
''' On save, add timestamps '''
|
||||
|
@ -206,3 +212,4 @@ class PrePlacementOffer(models.Model):
|
|||
tier = models.CharField(blank=False, choices=TIERS, max_length=10)
|
||||
designation = models.CharField(blank=False, max_length=25, default=None, null=True)
|
||||
accepted = models.BooleanField(default=None, null=True)
|
||||
history = HistoricalRecords()
|
||||
|
|
|
@ -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!
|
||||
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
|
||||
|
||||
|
@ -44,7 +44,8 @@ INSTALLED_APPS = [
|
|||
'rest_framework',
|
||||
'corsheaders',
|
||||
'django_db_logger',
|
||||
'background_task'
|
||||
'background_task',
|
||||
'simple_history',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -57,7 +58,7 @@ MIDDLEWARE = [
|
|||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
|
||||
'simple_history.middleware.HistoryRequestMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'CDC_Backend.urls'
|
||||
|
|
Loading…
Reference in New Issue