Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Django Admin search fields #557

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions parking_permits/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@

@admin.register(Address)
class AddressAdmin(admin.GISModelAdmin):
search_fields = ("street_name", "street_name_sv", "city", "city_sv")
search_fields = (
"id",
"street_name",
"street_name_sv",
"city",
"city_sv",
"postal_code",
)
list_display = (
"id",
"street_name",
Expand All @@ -49,6 +56,7 @@ class AddressAdmin(admin.GISModelAdmin):

@admin.register(Announcement)
class AnnouncementAdmin(admin.ModelAdmin):
search_fields = ("id", "subject_en", "subject_fi", "subject_sv")
list_display = (
"id",
"subject_en",
Expand All @@ -69,7 +77,13 @@ class CompanyAdmin(admin.ModelAdmin):

@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
search_fields = ("first_name", "last_name")
search_fields = (
"id",
"first_name",
"last_name",
"national_id_number",
"email",
)
list_display = (
"__str__",
"id",
Expand All @@ -92,7 +106,11 @@ class DrivingClassAdmin(admin.ModelAdmin):

@admin.register(DrivingLicence)
class DrivingLicenceAdmin(admin.ModelAdmin):
search_fields = ("customer__first_name", "customer__last_name")
search_fields = (
"customer__first_name",
"customer__last_name",
"customer__national_id_number",
)
list_display = ("id", "customer", "start_date", "end_date", "active")
list_select_related = ("customer",)

Expand Down Expand Up @@ -165,6 +183,7 @@ def latest_order(self, instance):
class ParkingPermitEventAdmin(admin.ModelAdmin):
date_hierarchy = "created_at"
search_fields = (
"parking_permit__id",
"parking_permit__customer__first_name",
"parking_permit__customer__last_name",
"parking_permit__customer__national_id_number",
Expand All @@ -180,6 +199,7 @@ class ParkingPermitEventAdmin(admin.ModelAdmin):

@admin.register(ParkingZone)
class ParkingZoneAdmin(admin.GISModelAdmin):
search_fields = ("name", "description", "description_sv")
list_display = ("id", "name", "description", "description_sv")
ordering = ("name",)

Expand All @@ -205,6 +225,7 @@ def get_form(self, request, obj=None, **kwargs):

@admin.register(Refund)
class RefundAdmin(admin.ModelAdmin):
search_fields = ("name", "iban", "orders__id")
list_display = (
"name",
"iban",
Expand Down Expand Up @@ -252,6 +273,7 @@ class AccountingAdmin(admin.ModelAdmin):

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
search_fields = ("zone__name",)
list_display = (
"zone",
"type",
Expand All @@ -273,6 +295,14 @@ class ProductAdmin(admin.ModelAdmin):

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
search_fields = (
"id",
"customer__last_name",
"customer__first_name",
"customer__national_id_number",
"talpa_order_id",
"vehicles",
)
list_filter = ("status", "type")
list_display = (
"id",
Expand All @@ -283,19 +313,14 @@ class OrderAdmin(admin.ModelAdmin):
"parking_zone_name",
"vehicles",
"get_vat_percents",
"talpa_order_id",
)
list_select_related = ("customer",)
readonly_fields = (
"talpa_order_id",
"total_payment_price",
"get_vat_percents",
)
search_fields = (
"customer__last_name",
"customer__first_name",
"customer__national_id_number",
"talpa_order_id",
)
raw_id_fields = (
"customer",
"created_by",
Expand All @@ -315,6 +340,14 @@ def get_vat_percents(self, obj):

@admin.register(OrderItem)
class OrderItemAdmin(admin.ModelAdmin):
search_fields = (
"id",
"order__id",
"talpa_order_item_id",
"order__talpa_order_id",
"subscription__talpa_subscription_id",
"permit__id",
)
raw_id_fields = ("permit", "order", "product", "subscription")
list_display = (
"order",
Expand All @@ -325,6 +358,7 @@ class OrderItemAdmin(admin.ModelAdmin):
"payment_unit_price",
"quantity",
"get_vat_percent",
"talpa_order_item_id",
)
list_select_related = ("order", "subscription", "product", "permit")
readonly_fields = ("talpa_order_item_id",)
Expand All @@ -337,21 +371,26 @@ def get_vat_percent(self, obj):

@admin.register(ParkingPermitExtensionRequest)
class ParkingPermitExtensionRequestAdmin(admin.ModelAdmin):
raw_id_fields = ("permit", "order")
list_filter = ("status",)
ordering = ("-created_at",)
search_fields = (
"permit__id",
"permit__customer__first_name",
"permit__customer__last_name",
"permit__vehicle__registration_number",
)
raw_id_fields = ("permit", "order")
list_filter = ("status",)
ordering = ("-created_at",)
list_display = ("permit", "status", "month_count")
list_select_related = True


@admin.register(Subscription)
class SubscriptionAdmin(admin.ModelAdmin):
search_fields = (
"id",
"talpa_subscription_id",
"order_items__talpa_order_item_id",
)
list_filter = ("status",)
list_display = (
"id",
Expand All @@ -376,7 +415,9 @@ def get_talpa_order_item_id(self, obj):

@admin.register(TemporaryVehicle)
class TemporaryVehicleAdmin(admin.ModelAdmin):
search_fields = ("id", "vehicle__registration_number")
list_display = (
"id",
"vehicle",
"start_time",
"end_time",
Expand All @@ -387,6 +428,10 @@ class TemporaryVehicleAdmin(admin.ModelAdmin):

@admin.register(VehicleUser)
class VehicleUserAdmin(admin.ModelAdmin):
search_fields = (
"national_id_number",
"vehicles__registration_number",
)
list_display = ("national_id_number", "get_vehicles")
ordering = ("national_id_number",)

Expand All @@ -409,4 +454,4 @@ def get_vehicles(self, obj):
@admin.register(StatusLog)
class ParkingPermitsStatusLogAdmin(StatusLogAdmin):
search_fields = ("msg",) # Add search field for the message
list_per_page = 20
list_per_page = 30