bot upgraded
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
from django.contrib import admin
|
||||
from .models import Hotel, UserHotel, APIConfiguration, APIRequestLog, PMSConfiguration, PMSIntegrationLog
|
||||
from django import forms
|
||||
from .models import (
|
||||
Hotel,
|
||||
UserHotel,
|
||||
APIConfiguration,
|
||||
APIRequestLog,
|
||||
PMSConfiguration,
|
||||
PMSIntegrationLog,
|
||||
Reservation,
|
||||
Guest
|
||||
)
|
||||
|
||||
# Custom form for Hotel to filter APIConfiguration
|
||||
class HotelForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Hotel
|
||||
@@ -8,49 +19,72 @@ class HotelForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# Исключаем API, которые уже связаны с другими отелями
|
||||
# Exclude APIs already linked to another hotel
|
||||
used_apis = Hotel.objects.exclude(api__isnull=True).values_list('api', flat=True)
|
||||
self.fields['api'].queryset = APIConfiguration.objects.exclude(id__in=used_apis)
|
||||
|
||||
|
||||
class HotelAdmin(admin.ModelAdmin):
|
||||
form = HotelForm
|
||||
list_display = ('name', 'api', 'created_at', 'pms')
|
||||
search_fields = ('name',)
|
||||
list_filter = ('pms', 'created_at')
|
||||
ordering = ('-created_at',)
|
||||
|
||||
admin.site.register(Hotel, HotelAdmin)
|
||||
|
||||
|
||||
@admin.register(UserHotel)
|
||||
class UserHotelAdmin(admin.ModelAdmin):
|
||||
list_display = ('user', 'hotel')
|
||||
search_fields = ('user', 'hotel')
|
||||
search_fields = ('user__username', 'hotel__name')
|
||||
list_filter = ('hotel',)
|
||||
ordering = ('-hotel',)
|
||||
|
||||
|
||||
|
||||
|
||||
@admin.register(APIConfiguration)
|
||||
class ApiConfigurationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'url', 'token', 'username', 'password')
|
||||
search_fields = ('name', 'url', 'token', 'username', 'password')
|
||||
list_filter = ('name', 'url', 'token', 'username', 'password')
|
||||
ordering = ('-name',)
|
||||
|
||||
list_display = ('name', 'url', 'token', 'username', 'password', 'last_updated')
|
||||
search_fields = ('name', 'url', 'token', 'username')
|
||||
list_filter = ('last_updated',)
|
||||
ordering = ('-last_updated',)
|
||||
|
||||
|
||||
@admin.register(APIRequestLog)
|
||||
class ApiRequestLogAdmin(admin.ModelAdmin):
|
||||
list_display = ('api', 'request_time', 'response_status', 'response_data')
|
||||
search_fields = ('api', 'request_time', 'response_status', 'response_data')
|
||||
list_filter = ('api', 'request_time', 'response_status', 'response_data')
|
||||
ordering = ('-api',)
|
||||
|
||||
|
||||
search_fields = ('api__name', 'request_time', 'response_status')
|
||||
list_filter = ('api', 'response_status', 'request_time')
|
||||
ordering = ('-request_time',)
|
||||
|
||||
|
||||
@admin.register(PMSConfiguration)
|
||||
class PMSConfigurationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'parser_settings', 'description')
|
||||
|
||||
list_display = ('name', 'parser_settings', 'description', 'created_at')
|
||||
search_fields = ('name', 'description')
|
||||
list_filter = ('created_at',)
|
||||
ordering = ('-created_at',)
|
||||
|
||||
|
||||
@admin.register(PMSIntegrationLog)
|
||||
class PMSIntegreationLogAdmin(admin.ModelAdmin):
|
||||
class PMSIntegrationLogAdmin(admin.ModelAdmin):
|
||||
list_display = ('hotel', 'checked_at', 'status', 'message')
|
||||
search_fields = ('hotel', 'checked_at', 'status', 'message')
|
||||
list_filter = ('hotel', 'checked_at', 'status', 'message')
|
||||
search_fields = ('hotel__name', 'status', 'message')
|
||||
list_filter = ('status', 'checked_at')
|
||||
ordering = ('-checked_at',)
|
||||
|
||||
|
||||
|
||||
@admin.register(Reservation)
|
||||
class ReservationAdmin(admin.ModelAdmin):
|
||||
list_display = ('reservation_id', 'hotel', 'room_number', 'room_type', 'check_in', 'check_out', 'status', 'price', 'discount')
|
||||
search_fields = ('reservation_id', 'hotel__name', 'room_number', 'room_type', 'status')
|
||||
list_filter = ('status', 'check_in', 'check_out')
|
||||
ordering = ('-check_in',)
|
||||
|
||||
|
||||
@admin.register(Guest)
|
||||
class GuestAdmin(admin.ModelAdmin):
|
||||
list_display = ('reservation', 'name', 'birthdate', 'phone', 'email')
|
||||
search_fields = ('reservation__reservation_id', 'name', 'phone', 'email')
|
||||
list_filter = ('reservation',)
|
||||
ordering = ('-reservation',)
|
||||
|
||||
Reference in New Issue
Block a user