Skip to content

Commit

Permalink
Fix admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ltan02 committed Nov 28, 2023
1 parent 51a795d commit 3607366
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 18 deletions.
27 changes: 24 additions & 3 deletions backend/auction/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
from django.contrib import admin

from auction.models import Auction
from .models import Auction, AuctionItem

# Register your models here.
admin.site.register(Auction)

class AuctionAdmin(admin.ModelAdmin):
list_display = ("id", "name", "start_date", "end_date", "is_published")
search_fields = ("name",)
list_filter = ("is_published", "start_date", "end_date")
ordering = ("-start_date",)


class AuctionItemAdmin(admin.ModelAdmin):
list_display = ("id", "auction_id", "content_type", "object_id")
search_fields = ("auction_id__name", "content_type__model")
list_filter = ("auction_id", "content_type")

def formfield_for_foreignkey(self, db_field, request, **kwargs):
# This method can be used to filter foreign key choices in the admin
if db_field.name == "auction_id":
kwargs["queryset"] = Auction.objects.filter(is_published=True)
return super().formfield_for_foreignkey(db_field, request, **kwargs)


# Register your models here
admin.site.register(Auction, AuctionAdmin)
admin.site.register(AuctionItem, AuctionItemAdmin)
28 changes: 26 additions & 2 deletions backend/bid/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline

from auction.models import Auction

from .models import Bid

# Register your models here.
admin.site.register(Bid)

class BidAdmin(admin.ModelAdmin):
list_display = (
"id",
"amount",
"bidder",
"auction",
"content_type",
"object_id",
"created_at",
)
search_fields = ("bidder__username", "auction__name", "amount")
list_filter = ("auction", "bidder", "content_type")

def formfield_for_foreignkey(self, db_field, request, **kwargs):
# This method can be used to filter foreign key choices in the admin
if db_field.name == "auction":
kwargs["queryset"] = Auction.objects.filter(is_published=True)
return super().formfield_for_foreignkey(db_field, request, **kwargs)


# Register your models here
admin.site.register(Bid, BidAdmin)
42 changes: 39 additions & 3 deletions backend/user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

from .models import Admin, Bidder

# Register your models here.
admin.site.register(Admin)
admin.site.register(Bidder)

class AdminAdmin(admin.ModelAdmin):
list_display = (
"id",
"email",
"first_name",
"last_name",
"permission_level",
"created_at",
)
search_fields = ("email", "first_name", "last_name")
list_filter = ("permission_level",)


class BidderAdmin(admin.ModelAdmin):
list_display = (
"id",
"email",
"first_name",
"last_name",
"company_name",
"bidder_number",
"is_verified",
"is_blacklisted",
"created_at",
)
search_fields = (
"email",
"first_name",
"last_name",
"company_name",
"bidder_number",
)
list_filter = ("is_verified", "is_blacklisted")


# Register your models here
admin.site.register(Admin, AdminAdmin)
admin.site.register(Bidder, BidderAdmin)
111 changes: 101 additions & 10 deletions backend/vehicle/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,104 @@
from django.contrib import admin

from .models import (
Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle)

# Register your models here.
admin.site.register(Brand)
admin.site.register(Type)
admin.site.register(Vehicle)
admin.site.register(Equipment)
admin.site.register(Supplier)
admin.site.register(Trailer)
admin.site.register(UnitImage)
Brand, Equipment, SavedUnits, Supplier, Trailer, Type, UnitImage, Vehicle)


class BrandAdmin(admin.ModelAdmin):
list_display = ("id", "name", "created_at")
search_fields = ("name",)


class TypeAdmin(admin.ModelAdmin):
list_display = ("id", "name", "created_at")
search_fields = ("name",)


class VehicleAdmin(admin.ModelAdmin):
list_display = (
"id",
"unicode_id",
"model_number",
"chassis_number",
"brand",
"vehicle_type",
"is_sold",
"created_at",
)
search_fields = (
"model_number",
"chassis_number",
"brand__name",
"vehicle_type__name",
)
list_filter = ("brand", "vehicle_type", "is_sold")


class EquipmentAdmin(admin.ModelAdmin):
list_display = (
"id",
"unicode_id",
"prefix_id",
"chassis_number",
"engine_number",
"brand",
"equipment_type",
"created_at",
)
search_fields = (
"prefix_id",
"chassis_number",
"engine_number",
"brand__name",
"equipment_type__name",
)
list_filter = ("brand", "equipment_type")


class SupplierAdmin(admin.ModelAdmin):
list_display = ("id", "name", "created_at")
search_fields = ("name",)


class TrailerAdmin(admin.ModelAdmin):
list_display = (
"id",
"unicode_id",
"chassis_number",
"supplier",
"trailer_type",
"number_of_axles",
"created_at",
)
search_fields = ("chassis_number", "supplier__name", "trailer_type__name")
list_filter = ("supplier", "trailer_type")


class UnitImageAdmin(admin.ModelAdmin):
list_display = ("id", "image_url", "content_type", "object_id", "created_at")
search_fields = ("content_type__model",)
list_filter = ("content_type",)


class SavedUnitsAdmin(admin.ModelAdmin):
list_display = (
"id",
"bidder_id",
"auction_id",
"content_type",
"object_id",
"created_at",
)
search_fields = ("bidder_id__first_name", "auction_id__name", "content_type__model")
list_filter = ("auction_id", "bidder_id", "content_type")


# Register your models here
admin.site.register(Brand, BrandAdmin)
admin.site.register(Type, TypeAdmin)
admin.site.register(Vehicle, VehicleAdmin)
admin.site.register(Equipment, EquipmentAdmin)
admin.site.register(Supplier, SupplierAdmin)
admin.site.register(Trailer, TrailerAdmin)
admin.site.register(UnitImage, UnitImageAdmin)
admin.site.register(SavedUnits, SavedUnitsAdmin)

0 comments on commit 3607366

Please sign in to comment.