在我的django管理员中我有一些外键,我可以随时添加和编辑这些字段,但有时我也可以删除它们。
在附图中显示Kategorie hotelu
和Wojewodztwo
有这个小红叉,其中Galeria zdjec
和Miasto
没有它。
为什么?如何将这个小红叉添加到我的Galeria zdjec
?
此处还请求管理员
-*- coding: utf-8 -*-
from django.contrib.gis import admin
from django.contrib.gis.geos import Point
from django.utils.safestring import mark_safe
from hotels.models import HotelCategory, Hotel, DescriptionInlines
from django.utils import timezone
from django_select2.forms import Select2Widget
from django import forms
from image_cropping.widgets import ImageCropWidget
class StackedinlineForm(forms.ModelForm):
class Meta:
model = DescriptionInlines
fields = '__all__'
class HotelAdminForm(forms.ModelForm):
class Meta:
model = Hotel
fields = '__all__'
widgets = {
'city': Select2Widget,
'gallery': Select2Widget,
'main_image': ImageCropWidget,
'logotype': ImageCropWidget
}
def clean(self):
premium_status = self.data.get('premium_status', None)
display_on_main_page = self.data.get('display_on_main_page', None)
if display_on_main_page and not premium_status:
raise forms.ValidationError(
(mark_safe(u"Nie można wyświetlać hotelu na stronie głównej, który nie jest hotelem premium."))
)
class DescriptionInlinesAdmin(admin.StackedInline):
form = StackedinlineForm
model = DescriptionInlines
extra = 1
suit_classes = 'suit-tab suit-tab-cities'
pnt = Point(20.00, 52.00, srid=4326)
pnt.transform(3857)
class HotelAdmin(admin.OSMGeoAdmin):
form = HotelAdminForm
default_zoom = 6
default_lon, default_lat = pnt.coords
list_display = ['name', 'city', 'street_and_number', 'tv_status', 'wifi_status', 'spa_status',
'beach_status', 'breakfast_status', 'pool_status', 'premium_status', 'is_active',
'display_on_main_page',
]
list_filter = ['city', 'stars', 'tv_status', 'wifi_status', 'spa_status', 'beach_status', 'breakfast_status',
'pool_status', 'premium_status', 'display_on_main_page',
]
search_fields = ['name']
readonly_fields = ['visits', 'visits_unique']
inlines = (DescriptionInlinesAdmin, )
filter_horizontal = ['tags', ]
exclude = ('slug', )
suit_form_tabs = (
('general', u'Dane podstawowe'), ('cities', u'Dodatkowe opisy'), ('main_page', u'Obróbka zdjęć'),
)
fieldsets = [
(None, {
'classes': ('suit-tab', 'suit-tab-general',),
'fields': ['name', 'old_slug', 'display_on_main_page', 'main_image', 'logotype', 'stars', 'gallery', 'video',
'categories', 'voivodeship', 'city', 'postcode', 'street_and_number', 'phone', 'email',
'webpage', 'description', 'price_starting_at', 'booking_com_url', 'tv_status', 'wifi_status',
'spa_status', 'beach_status', 'breakfast_status', 'pool_status', 'premium_status',
'premium_end_date', 'distance_to_city', 'facebook_url', 'twitter_url', 'ok_url', 'vk_url',
'location', 'latitude', 'longitude', 'tags', 'visits_unique', ]
}),
(None, {
'classes': ('suit-tab', 'suit-tab-main_page',),
'fields': ['col4', ]
}),
]
def is_active(self, obj):
if not obj.premium_status:
return None
else:
if obj.premium_end_date:
if obj.premium_end_date >= timezone.now():
return True
else:
return False
else:
return False
is_active.short_description = u'Aktywny hotel premium'
is_active.boolean = True
class Media:
css = {
'all': ('/statics/css/select2.min.css',)
}
js = ('/statics/js/hotel_admin_select2.js',)
admin.site.register(HotelCategory)
admin.site.register(Hotel, HotelAdmin)
答案 0 :(得分:0)
on_delete=models.SET_NULL
曾为