A custom model field 'ColorField' which stores a hex color value like '#FFFFFF' and shows a Javascript color picker in the admin rather than a raw text field. It is written to work with the current trunk (i.e. after newforms-admin merge).
You'll need the ColorPicker2.js file found at [www.mattkruse.com](http://www.mattkruse.com/javascript/colorpicker/combined_compact_source.html) (his license prohibits including the file here). This should be placed in the 'js' folder of your admin media.
The snippet includes a python source file which can be placed wherever you wish, and a template which by default should be placed in a folder 'widget' somewhere on your template path. You can put it elsewhere, just update the path ColorWidget.render
The custom field at present does not validate that the text is a valid hex color value, that'd be a nice addition.
A script I wrote a little while ago to help speed up newforms-admin conversion.
From memory it works best when run from an old-forms installation, but it is still useful post-conversion. There are some features missing, but it's supposed to be a starter.
Just install this command and run:
./manange.py port2nfa > admin.py
(To install, copy the file to management/commands/port2nfa.py in an app somewhere)
Add-on for auth app of newforms-admin branch, adding more information about users and their groups at user and group list in admin interface. Also, nice example on customization of contributed django admin apps.
It adds the following to the user list interface: fields for is_superuser and is_staff, last login time; by default, short names of groups user is in (mousehover to see full names)
It adds the following to the to group list interface: list of users in your groups.
To enable, just put it somewhere and import it from your main urls.py:
import useradmin
In an admin custom view I had the requirement to modify the upload handlers.
However, the @staff_member_required locked the Files upload handlers as it uses the request.POST - see [Ticket 7654](http://code.djangoproject.com/ticket/7654).
These decorators can be used before other decorators to allow setting of the upload handlers.
Usage example:
@upload_handlers_insert(0, QuotaUploadHandler)
@staff_member_required
def upload(request):
pass
This is an update to [snippet 765](http://www.djangosnippets.org/snippets/765/) as I was having trouble getting it to work on branches/newforms-admin @ r7771.
There are just a few minor changes to the previous snippet, all simple stuff. I went ahead an added can_delete and can_order options that the previous snippet didn't include.
[More details in blog post](http://paltman.com/2008/06/29/edit-inline-support-for-generic-relations/).
This snippet shows how to disable fields in a edit page in the oldforms admin using jquery.
The idea is to add the javascript to the edit page using the `js` attribute of the model's `Admin` class. In this case jQuery and a custom javascript file are added.
The javascript sets the `disabled` attribute of the `name` field to `true` as soon as the document is ready.
A simple InlineModelAdmin class that enables you to edit models that are bound by the instance via a generic foreign key (`content_type`, `object_id` pair)
Use like:
class PlacementInlineOptions( generic.GenericTabularInline ):
model = Placement
extra = 2
ct_field_name = 'target_ct'
id_field_name = 'target_id'
Can be also found at #4667
**Attention: this snippet depends on jQuery library to works**
The Admin templates hierarchy does not allow you change the submit line (that buttons bar in the footer of the change view of a model class).
This code shows how to resolve this, using a simple javascript trick. You can read the code and implement using your favorite javascript library (instead of jQuery) or pure JavaScript.
This example regards to User Profile, a common used model class that adds custom fields to a user in the authentication system.
To use this, you must put this template code in a file with the following name:
templates/admin/auth/user/change_form.html
This snippet adds a select language drop down menu in the admin bar (just after Documentation link).
For this approach it's necessary to copy from admin templates the admin/base.html to the project templates (keeping the admin directory), changing just line 25 ad shown. Then it's necessary to create specified admin/change_language.html template.
**WARNING: a better version of this snippet you can see at [http://www.djangosnippets.org/snippets/1051/](http://www.djangosnippets.org/snippets/1051/)**
This filter spec is util only for who uses newforms-admin branch.
To use this, you need to extend the class ModelAdmin for your model class, like the MyClassAdmin class in the code, with attention to the following lines:
# Appends the filter
cl.filter_specs.insert(0, AlphabeticFilterSpec(cl.lookup_opts.get_field('name'),request,cl.params,self.model,self))
This javascript has the functionality of the 'Edit Object' bookmarklet as [described by James Bennett](http://www.b-list.org/weblog/2007/nov/07/bookmarklets/) but instead of putting it within a bookmarklet it creates a div on the page with a link to the main admin screen, an edit the object link, and logout link.
Just include the javascript on any page you want the links to show up on and make sure that the page is using the populate_xheaders function to provide the needed headers as [described here](http://www.b-list.org/weblog/2007/nov/07/bookmarklets/). The built in generic views provide the needed headers by default.
NOTE: this is for **newforms-admin**
I need edit links for items on my site, outside of the django admin -- however, I'm lazy, and don't want to build my own edit forms when there's a perfectly nice admin already there.
Trick is, I need to be able to click a link to the django admin edit page for an item, and have it return to the calling page after saving.
This chunk of code does the trick (the "real" version extra cruft, naturally) -- the links will bring up the django admin editor, then return to the calling page after saving.
**Problem:**
A large project has lots of apps, so naturally you want a twin column admin interface, with the history out beyond those two columns...
**Solution:**
Involved editing the admin/index.html template, a simple modification to the adminapplist template tag, and a flag placed in each models.py for models you want in column two.
**Instructions:**
1. Create the app templates/admin/index.html file by copying and pasting the provided code.
2. Copy django/contrib/admin/templatetags/adminapplist.py to your app/templatetags directory as column_adminapplist.py and edit as shown in the provided code.
3. add a \_admin\_index\_column = 2 near the top of each models.py file for each one you want to be on the right hand side.