-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
190 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |