mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-16 22:09:27 +08:00
Improve transaction serializer and add user id to django admin list view in admin panel
This commit is contained in:
parent
9d2f777ffc
commit
9443631102
2 changed files with 6 additions and 5 deletions
|
@ -6,7 +6,8 @@ from .models import CustomUser
|
||||||
|
|
||||||
class CustomUserAdmin(UserAdmin):
|
class CustomUserAdmin(UserAdmin):
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
list_display = UserAdmin.list_display + ('is_technician', 'is_teacher')
|
list_display = UserAdmin.list_display + \
|
||||||
|
('is_technician', 'is_teacher', 'id')
|
||||||
fieldsets = UserAdmin.fieldsets + (
|
fieldsets = UserAdmin.fieldsets + (
|
||||||
(None, {'fields': ('is_technician', 'is_teacher')}),
|
(None, {'fields': ('is_technician', 'is_teacher')}),
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,10 +58,10 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
# Any transactions created will be associated with the one sending the POST/CREATE request
|
# Any transactions created will be associated with the one sending the POST/CREATE request
|
||||||
user = self.context['request'].user
|
user = self.context['request'].user
|
||||||
validated_data.data['borrower'] = user
|
validated_data['borrower'] = user
|
||||||
|
|
||||||
# All created transactions will be labelled as Pending
|
# All created transactions will be labelled as Pending
|
||||||
validated_data['transaction_status'] = 'Pending'
|
validated_data['transaction_status'] = 'Pending Approval'
|
||||||
|
|
||||||
# If no teacher responsible for the borrow transaction is selected, raise an error
|
# If no teacher responsible for the borrow transaction is selected, raise an error
|
||||||
if 'teacher' not in validated_data:
|
if 'teacher' not in validated_data:
|
||||||
|
@ -101,10 +101,10 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
equipments = validated_data['equipments']
|
equipments = validated_data['equipments']
|
||||||
for equipment in equipments:
|
for equipment in equipments:
|
||||||
existing__pending_transactions = Transaction.objects.filter(
|
existing__pending_transactions = Transaction.objects.filter(
|
||||||
equipments=equipment, transaction_status__in=['Pending', 'Approved', 'Borrowed', 'With Breakages: Pending Resolution'])
|
equipments=equipment, transaction_status__in=['Pending Approval', 'Approved', 'Borrowed', 'With Breakages: Pending Resolution', 'Returned: Pending Checking'])
|
||||||
if existing__pending_transactions.exists():
|
if existing__pending_transactions.exists():
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
f"Cannot add Equipment #{equipment.id}. It is still part of a non-finalized transaction")
|
f"Cannot add Equipment ID:{equipment.id}. It is still part of a non-finalized transaction")
|
||||||
|
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue