I have a general question to the django-admin.
Is it possible to react on form changes?
I have a select field in my django-admin detail site. Whenever i change the data from the select field, i want to change fields which are readonly.
Anybody ever dealed with this issue?
Thanks and Greetings
How to change ‘Django administration’ text? ¶ By default Django admin shows ‘Django administration’. You have been asked to replace this with ‘UMSRA Administration’ The text is at these pages: 1.1. Login, Listview and Changeview Page ¶ By default it looks like this and is set to “Django administration” site_header can be set to change this. 1.2.
The ModelAdmin class is the representation of a model in the admin interface. Usually, these are stored in a file named admin.py in your application. Let’s take a look at an example of the ModelAdmin: from django.contrib import admin from myapp.models import Author class AuthorAdmin(admin.ModelAdmin): pass admin.site.register(Author, AuthorAdmin)
In the context of a web application, ‘form’ might refer to that HTML <form>, or to the Django Form that produces it, or to the structured data returned when it is submitted, or to the end-to-end working collection of these parts. At the heart of this system of components is Django’s Form class.
A Django administrative site is represented by an instance of django.contrib.admin.sites.AdminSite; by default, an instance of this class is created as django.contrib.admin.site and you can register your models and ModelAdmin instances with it. If you want to customize the default admin site, you can override it.
My two cents:
As any other guys said it is a javascript
work. In admin pages Django pases jquery
. It is called django.jQuery
. So basilly you would do what @Ashfaq suggested. You will create a custom_script.js
and added to the Media
metaclass.
Basically(as @Ashfaq):
class MyModelAdmin(admin.ModelAdmin):
class Media:
js = ("js/custom_script.js",)
and custom_script.js
will be something like this(assuming that your select
field is called id_category
):
django.jQuery( document ).ready(function() {
console.log( "ready!" );
django.jQuery('#id_category').change(function() {
alert( "Handler for #id_category was called." );
});
});
The ready
function will guarantee the handler is getting set.
I think the thing that will work here is to add jQuery + your custom javascript and play with the events / clicks what-ever you want with elements.
class MyModelAdmin(admin.ModelAdmin):
class Media:
js = ("js/custom_script.js",)
in custom_script you can add click or change events as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With