Answer the question
In order to leave comments, you need to log in
Can someone explain how django passes request to request, queryset to queryset, if I add one more argument, what will happen there?
@admin.register(Movie)
class MovieAdmin(admin.ModelAdmin):
"""Фильмы"""
prepopulated_fields = {'slug': ('title',)}
list_display = ("title", "category", "slug", "draft")
list_filter = ("category", "year")
search_fields = ("title", "category__name")
inlines = [MovieShotsInline, ReviewInline]
save_on_top = True
save_as = True
list_editable = ("draft",)
actions = ['unpublish', 'publish']
form = MovieAdminForm
readonly_fields = ('get_image',)
fieldsets = (
(None, {
"fields": ("title",)
}),
(None, {
"fields": ("descriptions", ("image", 'get_image'))
}),
(None, {
"fields": (("year", "world_premiere", "country"),)
}),
("Actors", {
"classes": ("collapse",),
"fields": (("actors", "directors", "genres", "category"),)
}),
(None, {
"fields": (("budget", "fees_in_usa", "fees_in_world"),)
}),
("Options", {
"fields": (("slug", "draft"),)
}),
)
def get_image(self, obj):
"""Вывод постера"""
return mark_safe(f"<img src={obj.image.url} width='100' height='110'>")
def unpublish(self, request, queryset):
"""Снять с публикации"""
row_update = queryset.update(draft=True)
print(type(request))
if row_update == 1:
message_bit = "1 одна запись была обновлена"
else:
message_bit = f"{row_update} записей было изменено"
self.message_user(request, f"{message_bit}")
def publish(self, request, queryset):
""" Опубликовать """
row_update = queryset.update(draft=False)
if row_update == 1:
message_bit = "1 одна запись была обновлена"
else:
message_bit = f"{row_update} записей было изменено"
self.message_user(request, f"{message_bit}")
publish.short_description = 'Опубликовать'
publish.allowed_permissions = ('change',)
unpublish.short_description = 'Снять с публикации'
unpublish.allowed_permissions = ('change',)
get_image.short_description = 'Постер'
Answer the question
In order to leave comments, you need to log in
Learning to read the docs, the parameters are explicitly specified there https://docs.djangoproject.com/en/3.1/ref/contrib/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question