“Tambahkan tombol baru di indeks wagtail halaman” Kode Jawaban

Tambahkan tombol baru di indeks wagtail halaman

class ProductAdmin(ProductModelAdmin):
    model = Product
    button_helper_class = ProductButtonHelper
Fantastic Ferret

Tambahkan tombol baru di indeks wagtail halaman

from wagtail.contrib.modeladmin.helpers import ButtonHelper

class ProductButtonHelper(ButtonHelper):

    # Define classes for our button, here we can set an icon for example
    view_button_classnames = ['button-small', 'icon', 'icon-site'] 

    def view_button(self, obj):
        # Define a label for our button
        text = 'View {}'.format(self.verbose_name)
        return {
            'url': obj.get_absolute_url(), # decide where the button links to
            'label': text,
            'classname': self.finalise_classname(self.view_button_classnames),
            'title': text,
        }

    def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None, classnames_exclude=None):
        """
        This function is used to gather all available buttons.
        We append our custom button to the btns list.
        """
        btns = super().get_buttons_for_obj(obj, exclude, classnames_add, classnames_exclude)
        if 'view' not in (exclude or []):
            btns.append(
                self.view_button(obj)
            )
        return btns
Fantastic Ferret

Tambahkan tombol baru di indeks wagtail halaman

from django.contrib.admin import ModelAdmin

class ProductAdmin(ModelAdmin):
   model = Product
Fantastic Ferret

Jawaban yang mirip dengan “Tambahkan tombol baru di indeks wagtail halaman”

Pertanyaan yang mirip dengan “Tambahkan tombol baru di indeks wagtail halaman”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya