How to implement pygment syntax highlighting in django admin change_form? - python

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.

Related

Django ArrayField on Frontend Form?

I'm currently in the process of rebuilding my WordPress website into a full Django web app. With WordPress, I had made great use of the awesome Advanced Custom Fields plugin, and I'm struggling to get the same functionality with Django. One field in particular with ACF is called a "Repeater Field" that lets me click a button to add another row to an array.
I did manage to get something similar working with Django, but only in the Admin part. I've used this plugin "Django Better Admin ArrayField" - https://github.com/gradam/django-better-admin-arrayfield and it displays the arrayfield exactly as I want:
Django Better Admin ArrayField
How can I get this to work on the frontend of the site, like in a user-submitted form?

How to create a custom filter template in the Django admin interface?

My goal is to put a custom input field in the filter list box on my Django interface. I found no way of doing this with standard tools so I want to create a new template for the filter box.
In the official Django doc on the admin interface, there's this:
It is possible to specify a custom template for rendering a list filter:
class FilterWithCustomTemplate(admin.SimpleListFilter):
template = "custom_template.html"
See the default template provided by Django (admin/filter.html) for a concrete example.
But no more details are given. How am I supposed to implement this? filter.html does not extend change_list.html and I don't know where I am supposed to put my new custom filter template (I tried in templates/admin/my_app_name with the rest of my other overriding templates but it doesn't work)
How can I create a new template for my admin filter box ?

How to add HTML content editor in Django admin view?

How would I add a rich-text HTML content editor in my Django admin view?
For example, if I want to change the content on my homepage, what python code would I have to input for the HTML to be displayed when I log into the admin portal?
I want to be able to view all of my pages (hopefully even be able to add/delete them), and edit the content directly from the admin view. Similar to something like this:
http://feincms-django-cms.readthedocs.org/en/latest/_images/item_editor_content.png
I appreciate any and all help! Thank you!
The html shown there is there cuz it is in the database. If what you want is a cms, there are several of those for django like django-cms, wagtail, mezzanine among others.
If, on the other hand, you have a model already and want to display it in the admin, you can register it:
from django.contrib import admin
from myproject.myapp.models import Author
class AuthorAdmin(admin.ModelAdmin):
pass
admin.site.register(Author, AuthorAdmin)
In that example, the Author model will show up in admin for edition.
In the last case, where you already have your model registered but you want to have a WYSIWYG editor, check the django-grid for that kind of package and find one suitable, or install one manually.
You have several options in case you want to try the second approach: ckeditor, tinymce, etc.

How to add link at top of django admin list

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

Django: Add my own form to the admin backend?

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.

Categories

Resources