Login

Tag "admin"

Snippet List

Custom color field with Javascript color picker

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.

  • newforms
  • javascript
  • models
  • admin
Read More

Admin definition converter (for newforms-admin)

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)

  • newforms
  • admin
  • command
Read More

More information about users and groups in user admin

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

  • admin
  • newforms-admin
  • customization
  • users
  • groups
  • roles
  • information
  • nfa
  • supervising
Read More

upload handler decorators

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

  • admin
  • decorator
  • file
  • uploadhandler
Read More

EditInline for GenericForiegnKey II

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/).

  • admin
  • foreignkey
  • generic
  • edit-inline
Read More

Disable fields in oldforms admin using jQuery

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.

  • admin
  • jquery
  • oldforms
  • disable
Read More

Generic CSV Export

This will generically add csv exporting to your views in the admin. It will default to exporting the entire table you see (without paging). If the table only has one column, it will export the fields the the model. You can overide this functionality. I ended up creating my own admin/change_list.html to apply this functionality universally: {% extends "admin/base_site.html" %} {% load adminmedia admin_list i18n %} {% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %} {% block bodyclass %}change-list{% endblock %} {% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> &rsaquo; {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %} {% block coltype %}flex{% endblock %} {% block content %} <div id="content-main"> {% block object-tools %} <ul class="object-tools"> <li><a href="csv/{%if request.GET%}?{{request.GET.urlencode}}{%endif%}" class="addlink">Export to CSV</a></li> {% if has_add_permission %} <li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li> {% endif %} </ul> {% endblock %} <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist"> {% block search %}{% search_form cl %}{% endblock %} {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} {% block filters %}{% filters cl %}{% endblock %} {% block result_list %}{% result_list cl %}{% endblock %} {% block pagination %}{% pagination cl %}{% endblock %} </div> </div> {% endblock %}

  • admin
  • export
  • csv
Read More

EditInline for GenericForeignKey

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

  • admin
  • foreignkey
  • generic
  • edit-inline
Read More

Adding buttons to submit line in a Admin page

**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

  • template
  • ajax
  • javascript
  • admin
  • query
Read More

Admin change language

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.

  • admin
  • language
  • change
Read More

AlphabeticFilterSpec

**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))

  • filter
  • admin
  • alphabetic
Read More

In page edit object links

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.

  • admin
  • edit-object-links
Read More

newforms-admin edit callback-url hook

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.

  • newforms
  • admin
  • url
  • newforms-admin
  • newformsadmin
  • edit
  • callback
  • hook
Read More

Twin column model admin index

**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.

  • admin
  • admin-panel
Read More

241 snippets posted so far.