Borrowing-TrackerBackend/equipment_tracker/transactions/admin.py

18 lines
698 B
Python

from django.contrib import admin
from .models import Transaction
from accounts.models import CustomUser
class TransactionAdmin(admin.ModelAdmin):
list_display = ('id', 'borrower', 'teacher', 'transaction_status')
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "borrower":
kwargs["queryset"] = CustomUser.objects.exclude(
is_technician=True).exclude(is_teacher=True)
elif db_field.name == "teacher":
kwargs["queryset"] = CustomUser.objects.filter(is_teacher=True)
return super().formfield_for_foreignkey(db_field, request, **kwargs)
admin.site.register(Transaction, TransactionAdmin)