mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2025-04-27 10:11:24 +08:00
Added subject field to transaction and course field to customuser
This commit is contained in:
parent
0b1c065a80
commit
2ddc9da179
12 changed files with 55 additions and 52 deletions
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.7 on 2023-12-08 14:41
|
||||
# Generated by Django 4.2.7 on 2023-12-29 10:09
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -20,7 +20,9 @@ class Migration(migrations.Migration):
|
|||
name='Transaction',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('remarks', models.TextField(max_length=512, null=True)),
|
||||
('transaction_status', models.CharField(choices=[('Pending Approval', 'Pending Approval'), ('Approved', 'Approved'), ('Rejected', 'Rejected'), ('Cancelled', 'Cancelled'), ('Borrowed', 'Borrowed'), ('Returned: Pending Checking', 'Returned: Pending Checking'), ('With Breakages: Pending Resolution', 'With Breakages: Pending Resolution'), ('Finalized', 'Finalized')], default='Pending', max_length=40)),
|
||||
('subject', models.TextField(max_length=128)),
|
||||
('timestamp', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('borrower', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='borrowed_transactions', to=settings.AUTH_USER_MODEL)),
|
||||
('equipments', models.ManyToManyField(to='equipments.equipmentinstance')),
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 4.2.7 on 2023-12-08 15:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('transactions', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='transaction',
|
||||
name='remarks',
|
||||
field=models.TextField(max_length=512, null=True),
|
||||
),
|
||||
]
|
|
@ -33,6 +33,7 @@ class Transaction(models.Model):
|
|||
equipments = models.ManyToManyField(EquipmentInstance)
|
||||
transaction_status = models.CharField(
|
||||
max_length=40, choices=TRANSACTION_STATUS_CHOICES, default='Pending')
|
||||
subject = models.TextField(max_length=128)
|
||||
timestamp = models.DateTimeField(default=now, editable=False)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -30,6 +30,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
|
|||
many=False, slug_field='id', queryset=CustomUser.objects.all(), required=True, allow_null=False)
|
||||
equipments = serializers.SlugRelatedField(
|
||||
many=True, slug_field='id', queryset=EquipmentInstance.objects.all(), required=True)
|
||||
subject = serializers.CharField(required=True, allow_null=False)
|
||||
timestamp = serializers.DateTimeField(
|
||||
format="%m-%d-%Y %I:%M %p", read_only=True)
|
||||
|
||||
|
@ -38,7 +39,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
fields = ['id', 'borrower', 'teacher',
|
||||
fields = ['id', 'borrower', 'teacher', 'subject',
|
||||
'equipments', 'remarks', 'transaction_status', 'timestamp']
|
||||
read_only_fields = ['id', 'timestamp']
|
||||
|
||||
|
@ -149,6 +150,13 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
|
|||
"You cannot change the equipments of an already created transaction"
|
||||
)
|
||||
|
||||
# Subject Validation
|
||||
# Do not allow changes to subject on created transactions
|
||||
if 'subject' in validated_data:
|
||||
raise serializers.ValidationError(
|
||||
"You cannot change the subject of an already created transaction"
|
||||
)
|
||||
|
||||
# Transaction Status Validation
|
||||
# Check if the update involves the transaction status
|
||||
if 'transaction_status' in validated_data:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue