Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add a new button in the index of the page wagtail

from django.contrib.admin import ModelAdmin

class ProductAdmin(ModelAdmin):
   model = Product
Comment

add a new button in the index of the page wagtail

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
Comment

add a new button in the index of the page wagtail

class ProductAdmin(ProductModelAdmin):
    model = Product
    button_helper_class = ProductButtonHelper
Comment

PREVIOUS NEXT
Code Example
Python :: cieling function pandas 
Python :: 52277-36880 
Python :: python code to fetch all the files with txt extension from a folder 
Python :: detail view use slug or anything else pk 
Python :: MultiValueDictKeyError at /user/register 
Python :: anaconda pytorch depencies windows 
Python :: files and exceptions not working python 
Python :: geting columnvalue in python df 
Python :: merge df datacamp 
Python :: 3.81/(1000*1000*100) 
Python :: numpy rolling 2d 
Python :: can we use python functions in node 
Python :: can we pickle pyspark dataframe using python 
Python :: How to estimate memory of dataset using python command 
Python :: wait_for_message definition 
Python :: TypeError at /admin/auth/user/ 
Python :: python script copy and paste 
Python :: pie auto percentage in python 
Python :: go to line in jetbrain 
Python :: Sort list in-place (Original list is modified) 
Python :: interval time specification 
Python :: python sns save plot lable axes 
Python :: javascript parse url with values and anchors 
Python :: how to make a relationship in python 
Python :: how to search for element in list python 
Python :: how to make celery create missing queue 
Python :: how to send one variable to python using xlwings 
Python :: how to filter csv file by columns 
Python :: semaphore example in python 
Python :: Lcd screen 3.5 inch to pi 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =