diff --git a/home/admin.py b/home/admin.py index a78a8ef..9b3139a 100644 --- a/home/admin.py +++ b/home/admin.py @@ -942,7 +942,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): "email__degree", "email__department", ) - list_display = ("student_id", "name", "email", "period", "caterer", "jain") + list_display = ("student_id", "name", "email", "period", "caterer", "jain", "registration_time",) fieldsets = ( ( None, @@ -957,6 +957,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): "first_pref", "second_pref", "third_pref", + "registration_time", ), "description": "%s" % ALLOCATION_DESC_TEXT, }, diff --git a/home/migrations/0004_allocation_registration_time.py b/home/migrations/0004_allocation_registration_time.py new file mode 100644 index 0000000..fea5c31 --- /dev/null +++ b/home/migrations/0004_allocation_registration_time.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.8 on 2024-09-03 16:13 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0003_allocationform_show_allocated'), + ] + + operations = [ + migrations.AddField( + model_name='allocation', + name='registration_time', + field=models.DateTimeField(blank=True, default=django.utils.timezone.now, help_text='This contains the time of registration', null=True, verbose_name='Registration time'), + ), + ] diff --git a/home/models/allocation.py b/home/models/allocation.py index d28068e..cf64cbf 100644 --- a/home/models/allocation.py +++ b/home/models/allocation.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import gettext as _ +from django.utils.timezone import now from .caterer import Caterer @@ -120,6 +121,14 @@ class Allocation(models.Model): null=True, blank=True, ) + registration_time = models.DateTimeField( + _("Registration time"), + default=now, + blank=True, + null=True, + help_text="This contains the date and time of registration", + editable=True, + ) def __str__(self): return self.student_id diff --git a/home/resources.py b/home/resources.py index eee6281..51f9782 100644 --- a/home/resources.py +++ b/home/resources.py @@ -1,6 +1,7 @@ import logging from import_export import fields, resources +from django.utils import timezone from .models import ( Allocation, @@ -78,6 +79,12 @@ class AllocationResource(resources.ModelResource): attribute="second_pref", column_name="Second Preferences" ) third_pref = fields.Field(attribute="third_pref", column_name="Third Preferences") + registration_time = fields.Field(attribute="registration_time", column_name="Registration Date Time") + + def dehydrate_registration_time(self, allocation): + # Convert the registration_time to local time + local_time = timezone.localtime(allocation.registration_time) + return local_time.strftime('%Y-%m-%d %H:%M:%S') class Meta: model = Allocation @@ -99,6 +106,7 @@ class Meta: "first_pref", "second_pref", "third_pref", + "registration_time", ) export_order = [ @@ -116,6 +124,7 @@ class Meta: "first_pref", "second_pref", "third_pref", + "registration_time", ] diff --git a/messWebsite/settings.py b/messWebsite/settings.py index 801a664..af61065 100644 --- a/messWebsite/settings.py +++ b/messWebsite/settings.py @@ -25,25 +25,30 @@ # Application definition INSTALLED_APPS = [ + # Django apps "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "django.contrib.sites", + "django.contrib.admindocs", + + # Third-party apps "import_export", "django_admin_logs", - "home.apps.HomeConfig", - "django.contrib.sites", "allauth", "allauth.account", "allauth.socialaccount", "allauth.socialaccount.providers.google", - "django.contrib.admindocs", "cloudinary_storage", "cloudinary", "apscheduler", "django_apscheduler", + + # Local apps + "home.apps.HomeConfig", ] MIDDLEWARE = [