Files
Touchh/hotels/admin.py

56 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.contrib import admin
from .models import Hotel, UserHotel, APIConfiguration, APIRequestLog, PMSConfiguration, PMSIntegrationLog
from django import forms
class HotelForm(forms.ModelForm):
class Meta:
model = Hotel
fields = "__all__"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Исключаем API, которые уже связаны с другими отелями
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',)
admin.site.register(Hotel, HotelAdmin)
@admin.register(UserHotel)
class UserHotelAdmin(admin.ModelAdmin):
list_display = ('user', 'hotel')
search_fields = ('user', 'hotel')
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',)
@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',)
@admin.register(PMSConfiguration)
class PMSConfigurationAdmin(admin.ModelAdmin):
list_display = ('name', 'parser_settings', 'description')
@admin.register(PMSIntegrationLog)
class PMSIntegreationLogAdmin(admin.ModelAdmin):
list_display = ('hotel', 'checked_at', 'status', 'message')
search_fields = ('hotel', 'checked_at', 'status', 'message')
list_filter = ('hotel', 'checked_at', 'status', 'message')
ordering = ('-checked_at',)