Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add help_text for search field in admin.py

How can I add help_text in django for a search field I am using in admin.py as:

class ProfileAdmin(admin.ModelAdmin):

    list_display = ('First_Name','Last_Name','Registeration_No','University','Batch','Sex')

    search_fields = ('First_Name','Last_Name','Registeration_No','University','Batch')
like image 496
Ankita Avatar asked Jul 10 '12 10:07

Ankita


People also ask

What is Admin py in Python?

The admin.py file is used to display your models in the Django admin panel. You can also customize your admin panel.

What is Django admin py?

django-admin.py is Django's command-line utility for administrative tasks. This document outlines all it can do. In addition, manage.py is automatically created in each Django project.


2 Answers

You can add this javascript in ModelAdmin

window.onload = function() {
    document.getElementById("searchbar").placeholder = "search with ";
};

ModelAdmin will be like

class SomeModelAdmin(admin.ModelAdmin):

    class Media:
        js = ('js/admin/custom_admin.js',)
        # css = { 'all': ('css/admin/custom_admin.css',)}

add the custom_admin.js in static/js/admin directory.

like image 103
javed Avatar answered Sep 17 '22 00:09

javed


You could either override Admin template admin/search_form.html to add help text;
Or load a javascript file, which could find the dom node to insert the help text, in ProfileAdmin.Media, check the doc.

like image 31
okm Avatar answered Sep 17 '22 00:09

okm