I would like to add a per-page selector in the list-view of ModelAdmin.
Like this:
I could not find anything specific to this in django admin docs: https://docs.djangoproject.com/en/1.9/ref/contrib/admin/
I've also tried list_per_page attribute.
I'm using Django 1.7.7.
Am I missing something from docs, or is there any 3rd party app available to achieve this?
I think you need to customize djnago admin. Use jQuery to solve purpose.
Use Jquery and hit a service with page=20 or page=50 and in view.py get records according ot passing param.
Related
I need to have a wagtail DateField disabled by default, but if the content author checks a box (a wagtail BooleanField) then the field should be enabled and required. I'm struggling to find the best way to solve this, I haven't found documentation on how to do this. I was thinking about using Django signals or wagtail hooks but it does seem like a complex solution for what I think should be a common use case. So I was wondering if anyone has a better alternative or point me to the right direction.
I don't believe this is possible currently in Wagtail (as of Wagtail 2.2). Not natively, at least.
What you can do, however, is add custom JavaScript to your admin with a snippet like this:
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.html import format_html
from wagtail.core import hooks
#hooks.register("insert_global_admin_js", order=100)
def global_admin_js():
"""Add custom.js to Wagtail Admin."""
return format_html('<script src="{}"></script>', static("js/custom.js"))
And then inside your custom.js file, you can add a JavaScript event to detect when the boolean field is checked or not, and then find and select the DateField and disable or hide it.
As Willem Van Onsem has mentioned, you'll want to make the DateField nullable and blank so you can save the Page (as a form) when the DateField is empty.
I want to pygmentize my text field python code in django admin template in a situation.
I have a python code block which is stored as a text field in django model.Here i stand with the situation of highlighting that python code with syntax in django admin change_form.html whenever you try to access that, it would be in proper syntax highlighiting style.
I have gone through some resources.
All are explained to make django template tag or filter with custom pygment template tag also, i got some nice article too.
1.http://od-eon.com/blogs/stefan/integrating-pygments-django/
2.http://djangosnippets.org/snippets/416/
But I am facing problem of using the template tags or filters in django admin change_form.html ?
Or How can we do the syntax highlighting through django model admin if this is the method should need to be passed (http://dpaste.com/hold/1280580/)?
Assuming you don't need ordering on the python code column, then you could simply render it using pygments API in a ModelAdmin method using list_display. Then you wouldn't need to touch django admin templates at all.
I want to do the following:
I want to add a "Refresh" link at the top of the django admin page for a model. How can I do that? I want when people click on Refresh they go to another page that gets data from Google analytics API.
How can I add a link at the top of the admin page for a model? Thanks!
What I tried:
I tried overriding the change_list template for the django admin, but that did not work.
Overriding the change_list template is really your only choice. Did you get errors? or did your content not show up? The hierarchy of your templates directory is directly related to how/where Django looks for templates.
Double check the documentation on overriding admin templates. You may have made a simple mistake: https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#overriding-admin-templates
By default, Django's admin renders ForeignKey fields in admin as a select field, listing every record in the foreign table as an option. In one admin-accessible model, I'm referencing the User model as a ForeignKey, and since I have thousands of users Django is populating the select with thousands of options. This is causing the admin page to load incredibly slowly, and the select is not very useful since it can take a while to scroll through thousands of options to find the one you want.
What's the best way to change the rendering of this field in order to improve page load and usability? I'd like the select field to be replaced with some sort of button to launch a search form popup, or a text field that searches keywords via Ajax to find the Id for the specific User they want to associate. Does admin have anything like this builtin, or would I have to write this from scratch?
Add raw_id_fields to your model to only show the ID instead of a dropdown.
You're right, Cerin, the cause of the slowdown is because Django is populating the <select> element with too many options. You might want to use an autocomplete element instead.
Interestingly, Django 2.0 has introduced a new feature on the admin site, called autocomplete_fields, which I think you will find useful in this case. It uses AJAX.
class ExampleAdmin(models.ModelAdmin):
autocomplete_fields = ['example_field_user']
You can use one of the few autocomplete apps for Django. Check them at Django Packages.
There's also django-extensions that have ForeignKeyAutocompleteAdmin that fit your needs pretty well.
Another option is to add readonly_fields instead of raw_id_fields
I'm using the Django Admin module. It displays a list of models to edit by app. I would like to add another form to this list. It won't edit a specific model, but it will edit settings that are stored in the database. Is this possible?
You may check out Django Live Settings. It was split out of the Satchmo project and looks to do what you're looking for.
Otherwise, you may look into Overriding the Django Admin Templates. You could just override the index template and add your links to the bottom.