mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2025-04-27 10:11:24 +08:00
Added transactions and updated models to reflect transactions
This commit is contained in:
parent
d915852632
commit
2c8cc87cbe
39 changed files with 635 additions and 291 deletions
11
equipment_tracker/equipments/choices.py
Normal file
11
equipment_tracker/equipments/choices.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
EQUIPMENT_CATEGORY_CHOICES = (
|
||||
('Glassware', 'Glassware'),
|
||||
('Miscellaneous', 'Miscellaneous')
|
||||
)
|
||||
|
||||
|
||||
EQUIPMENT_INSTANCE_STATUS_CHOICES = (
|
||||
('Working', 'Working'),
|
||||
('Broken', 'Broken'),
|
||||
('Borrowed', 'Borrowed'),
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.7 on 2023-12-02 12:25
|
||||
# Generated by Django 4.2.7 on 2023-12-08 14:41
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -21,18 +21,18 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=40)),
|
||||
('description', models.TextField(max_length=512)),
|
||||
('category', models.CharField(choices=[('Glassware', 'Glassware'), ('Miscellaneous', 'Miscellaneous')], default='Miscellaneous', max_length=20)),
|
||||
('description', models.TextField(max_length=512, null=True)),
|
||||
('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('last_updated', models.DateTimeField(auto_now=True)),
|
||||
('category', models.CharField(choices=[('PC', 'PC'), ('NETWORKING', 'Networking'), ('CCTV', 'CCTV'), ('FURNITURE', 'Furniture'), ('PERIPHERALS', 'Peripherals'), ('MISC', 'Miscellaneous')], default='MISC', max_length=20)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='HistoricalEquipmentInstance',
|
||||
fields=[
|
||||
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
|
||||
('status', models.CharField(choices=[('WORKING', 'Working'), ('BROKEN', 'Broken'), ('MAINTENANCE', 'Under Maintenance'), ('DECOMISSIONED', 'Decomissioned')], default='PENDING', max_length=20)),
|
||||
('remarks', models.TextField(max_length=512)),
|
||||
('status', models.CharField(choices=[('Working', 'Working'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='PENDING', max_length=20)),
|
||||
('remarks', models.TextField(max_length=512, null=True)),
|
||||
('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('last_updated', models.DateTimeField(blank=True, editable=False)),
|
||||
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||
|
@ -55,10 +55,10 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=40)),
|
||||
('description', models.TextField(max_length=512)),
|
||||
('category', models.CharField(choices=[('Glassware', 'Glassware'), ('Miscellaneous', 'Miscellaneous')], default='Miscellaneous', max_length=20)),
|
||||
('description', models.TextField(max_length=512, null=True)),
|
||||
('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('last_updated', models.DateTimeField(blank=True, editable=False)),
|
||||
('category', models.CharField(choices=[('PC', 'PC'), ('NETWORKING', 'Networking'), ('CCTV', 'CCTV'), ('FURNITURE', 'Furniture'), ('PERIPHERALS', 'Peripherals'), ('MISC', 'Miscellaneous')], default='MISC', max_length=20)),
|
||||
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('history_date', models.DateTimeField(db_index=True)),
|
||||
('history_change_reason', models.CharField(max_length=100, null=True)),
|
||||
|
@ -77,8 +77,8 @@ class Migration(migrations.Migration):
|
|||
name='EquipmentInstance',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('status', models.CharField(choices=[('WORKING', 'Working'), ('BROKEN', 'Broken'), ('MAINTENANCE', 'Under Maintenance'), ('DECOMISSIONED', 'Decomissioned')], default='PENDING', max_length=20)),
|
||||
('remarks', models.TextField(max_length=512)),
|
||||
('status', models.CharField(choices=[('Working', 'Working'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='PENDING', max_length=20)),
|
||||
('remarks', models.TextField(max_length=512, null=True)),
|
||||
('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('last_updated', models.DateTimeField(auto_now=True)),
|
||||
('equipment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='equipments.equipment')),
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
# Generated by Django 4.2.7 on 2023-12-02 13:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('equipments', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='equipment',
|
||||
name='description',
|
||||
field=models.TextField(max_length=512, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='equipmentinstance',
|
||||
name='remarks',
|
||||
field=models.TextField(max_length=512, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='historicalequipment',
|
||||
name='description',
|
||||
field=models.TextField(max_length=512, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='historicalequipmentinstance',
|
||||
name='remarks',
|
||||
field=models.TextField(max_length=512, null=True),
|
||||
),
|
||||
]
|
|
@ -3,26 +3,19 @@ from django.utils.timezone import now
|
|||
from simple_history.models import HistoricalRecords
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.dispatch import receiver
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Equipment(models.Model):
|
||||
|
||||
CATEGORY_CHOICES = (
|
||||
('PC', 'PC'),
|
||||
('NETWORKING', 'Networking'),
|
||||
('CCTV', 'CCTV'),
|
||||
('FURNITURE', 'Furniture'),
|
||||
('PERIPHERALS', 'Peripherals'),
|
||||
('MISC', 'Miscellaneous')
|
||||
EQUIPMENT_CATEGORY_CHOICES = (
|
||||
('Glassware', 'Glassware'),
|
||||
('Miscellaneous', 'Miscellaneous')
|
||||
)
|
||||
|
||||
name = models.CharField(max_length=40)
|
||||
category = models.CharField(
|
||||
max_length=20, choices=EQUIPMENT_CATEGORY_CHOICES, default='Miscellaneous')
|
||||
description = models.TextField(max_length=512, null=True)
|
||||
date_added = models.DateTimeField(default=now, editable=False)
|
||||
last_updated = models.DateTimeField(auto_now=True, editable=False)
|
||||
category = models.CharField(
|
||||
max_length=20, choices=CATEGORY_CHOICES, default='MISC')
|
||||
history = HistoricalRecords()
|
||||
|
||||
def __str__(self):
|
||||
|
@ -30,16 +23,14 @@ class Equipment(models.Model):
|
|||
|
||||
|
||||
class EquipmentInstance(models.Model):
|
||||
STATUS_CHOICES = (
|
||||
('WORKING', 'Working'),
|
||||
('BROKEN', 'Broken'),
|
||||
('MAINTENANCE', 'Under Maintenance'),
|
||||
('DECOMISSIONED', 'Decomissioned'),
|
||||
EQUIPMENT_INSTANCE_STATUS_CHOICES = (
|
||||
('Working', 'Working'),
|
||||
('Broken', 'Broken'),
|
||||
('Borrowed', 'Borrowed'),
|
||||
)
|
||||
|
||||
equipment = models.ForeignKey(Equipment, on_delete=models.CASCADE)
|
||||
status = models.CharField(
|
||||
max_length=20, choices=STATUS_CHOICES, default='PENDING')
|
||||
max_length=20, choices=EQUIPMENT_INSTANCE_STATUS_CHOICES, default='PENDING')
|
||||
remarks = models.TextField(max_length=512, null=True)
|
||||
date_added = models.DateTimeField(default=now, editable=False)
|
||||
last_updated = models.DateTimeField(auto_now=True, editable=False)
|
||||
|
@ -53,14 +44,14 @@ class EquipmentInstance(models.Model):
|
|||
def create_superuser(sender, **kwargs):
|
||||
if sender.name == 'equipments':
|
||||
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
||||
name="HP All-in-One PC", description="I5 6500 8GB RAM 1TB HDD", category="PC")
|
||||
name="Pyrex Beaker", description="", category="Glassware")
|
||||
EQUIPMENT_INSTANCE, CREATED = EquipmentInstance.objects.get_or_create(
|
||||
equipment=EQUIPMENT, status="WORKING", remarks="First PC of citc equipment tracker!")
|
||||
equipment=EQUIPMENT, status="Working", remarks="First beaker of equipment tracker!")
|
||||
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
||||
name="HP Keyboard", description="Generic Membrane Keyboard", category="PERIPHERALS")
|
||||
name="Bunsen Burner", description="", category="Miscellaneous")
|
||||
EQUIPMENT_INSTANCE, CREATED = EquipmentInstance.objects.get_or_create(
|
||||
equipment=EQUIPMENT, status="WORKING", remarks="First keyboard of citc equipment tracker!")
|
||||
equipment=EQUIPMENT, status="Working", remarks="First bunsen burner of equipment tracker!")
|
||||
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
||||
name="HP Mouse", description="Generic Mouse", category="PERIPHERALS")
|
||||
name="Microscope", description="", category="Miscellaneous")
|
||||
EQUIPMENT_INSTANCE, CREATED = EquipmentInstance.objects.get_or_create(
|
||||
equipment=EQUIPMENT, status="WORKING", remarks="First mouse of citc equipment tracker!")
|
||||
equipment=EQUIPMENT, status="Working", remarks="First microscope of equipment tracker!")
|
||||
|
|
|
@ -3,7 +3,6 @@ from .models import Equipment, EquipmentInstance
|
|||
from drf_spectacular.utils import extend_schema_field
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
from django.db.models import F
|
||||
from accounts.models import CustomUser
|
||||
|
||||
# -- Equipment Serializers
|
||||
|
||||
|
@ -104,7 +103,8 @@ class EquipmentInstanceSerializer(serializers.HyperlinkedModelSerializer):
|
|||
last_updated = serializers.DateTimeField(
|
||||
format="%m-%d-%Y %I:%M%p", read_only=True)
|
||||
last_updated_by = serializers.SerializerMethodField()
|
||||
status = serializers.ChoiceField(choices=EquipmentInstance.STATUS_CHOICES)
|
||||
status = serializers.ChoiceField(
|
||||
choices=EquipmentInstance.EQUIPMENT_INSTANCE_STATUS_CHOICES)
|
||||
|
||||
# Forbid user from changing equipment field once the instance is already created
|
||||
def update(self, instance, validated_data):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue