Login

Tag "admin"

Snippet List

YUI editor for flatpages inside admin interface

This template extends the change form for the flatpages inside the admin interface to use [Yahoo! User Interface Library](http://developer.yahoo.com/yui/)'s [Rich Text Editor](http://developer.yahoo.com/yui/editor/). It should be named `change_form.html` and be placed in the `admin/flatpages/flatpage/` directory of the project templates.

  • admin
  • flatpages
  • yui-editor
Read More

More informative error mailings

This middleware makes the admin error emails a lot more informative: you get the same HTML response that you get with `DEBUG=True`. It uses the base class defined in [#638](http://www.djangosnippets.org/snippets/638/). You will probably want to apply the patch for [#6748](http://code.djangoproject.com/ticket/6748) to help avoid slowdowns caused by unintentional database queries. As the ticket (and django-developers thread) notes, it isn't foolproof; you may still find this executing database queries.

  • admin
  • debug
  • error
  • mail
  • 500
Read More

Multiple Delete in Admin

This snippet demonstrates the use of the SpecialOps patch ( [link here](http://hackermojo.com/mt-static/archives/2008/02/django-special-ops.html) )to the django 0.96 admin. Once you have the patch, adding actions like these is simple. You can use the @admin_action decorator on model and manager methods to expose them inside the admin. For manager methods, the method should accept a list of IDs. For model methods, only self should be required.

  • admin
  • multiple
  • delete
  • hooks
Read More

Specify a manager for the Admin

This example shows how you can easily limit the objects in the admin by specifying which Manager the admin should use. I haven't seen this documented anywhere (perhaps I've missed it), but it's proven extremely useful to me. The example here will limit objects to those that are attached to the current Site, but you can use any Manager you want (for example, a Manager that shows only published Articles). Finally -- not that I'm suggesting this -- but you *could* combine this with the ThreadLocals trick to show only objects that have been created by that user.

  • managers
  • models
  • admin
  • sites
Read More

Group results by a range of values in admin sidebar

Adds filtering by ranges of values in the admin filter sidebar. This allows rows in numerical fields to be grouped together (in this case, group by price): By store price All < 100 100 - 200 200 - 500 500 - 2000 >= 200 **To use:** 1. save the code as rangevaluesfilterspec.py in your app's directory 2. add `import rangevaluesfilterspec` to your models.py 3. add `myfield.list_filter_range = [value1, value2, ...]` to your filter field **Example:** from django.db import models import rangevaluesfilterspec class Product(models.Model): store_price = models.DecimalField(max_digits=10, decimal_places=2) store_price.list_filter_range = [100, 200, 500, 2000] class Admin: list_filter = ['store_price'] Note that two extra groups are added: less-than the lowest value, and greater-than-or-equal-to the highest value.

  • filter
  • admin
  • sidebar
Read More

Add special field lookups to the Admin list_filter display

Ever wanted to add an atypical [field lookup](http://www.djangoproject.com/documentation/db-api/#field-lookups) to the Django Admin list_filter filters, like `__isnull` or `__in`? This jQuery snippet allows you to do just that. Since you can access those additional filters by directly typing them into in the Admin URL, the tricky part is to add those to the regular list_filter display. A lot of this code is spent checking on querystring matches which is ugly and error-prone -- if you see any problems or room for improvement, drop me a comment! A suggestion of where to place this code is in `templates/admin/yourapp/yourmodel/change_list.html`. Mine kinda looks like this: {% extends "admin/change_list.html" %} {% block content %} <script src="/static/js/jquery-1.2.2.min.js" type="text/javascript"></script> <script type="text/javascript"> // the JavaScript posted in this snippet </script> {{ block.super }} {% endblock %}

  • admin
  • jquery
Read More

Export Database and Media_Root via Admin Interface

This is the view-code to export a database-dump (hardcoded for mysql) or a media_root dump via the admin interface. just add 2 urls patterns to call the views and a small template with a simple form to send a http-post to the views. Note: The downloads are sort of streaming. I have successfully exportet a 2GB media_root as tar-ball without major increase of ram-usage of the django-process.

  • admin
  • export
  • database
  • media-root
Read More

Regrouping admin models

This is modification of Django's original adminapplist template tag. You can move your models from one app to other or completely hide them with this mod. Copy django_dir/contrib/admin/templates/admin/index.html file to your templates/admin folder, open it, then change {% load adminapplist %} to {% load custom_adminapplist %} (or whatever you named the templatetag file) After that, write your regrouping schema to settings.py file like this; UPDATED, now using tupples instead of dicts in APP_SCHEMA to make it more DRY. ` APP_SCHEMA=[ ( ['Model','List'], 'From App', 'To App', ), ( ['FlatPage'], 'Flatpages', 'Site Content', ), ( ['Product'] 'Product', 'Shop', ), ( ['Site'] 'Sites', #We are hiding Site model by not defining a target. ), ] `

  • templatetag
  • models
  • admin
  • app
Read More

Admin list_display Ajax

Sometimes it can be time consuming to go through a bunch of objects in Django's Admin if you only need to update one field in each. An example of this is an `order` field that allows you to manually set the order for a queryset. **This snippet contains examples of how to set up the Admin list_display to make Ajax calls to a custom view.** The following code may not be worthy of being a snippet, it's all pretty straightforward, but here it is for those who just want to copy-and-paste.

  • admin
  • jquery
Read More

Unobtrusvie Foldable Admin Interface

Inspired by [snippet 550](http://www.djangosnippets.org/snippets/550/), this allows you to expand or collapse apps in the main Admin screen. Requires jQuery. If jquery.cookie.js is available it will remember which apps you have expanded. Recommended usage: Place the JavaScript in a file called `admin-expand.js`. Create `templates/admin/base_site.html` in your templates directory (which is also a good place to [brand your Admin](http://djangobook.com/en/1.0/chapter06/#cn70)). Put the following code near the top, and you're done (adjusting file paths as needed). {% extends "admin/base.html" %} {% block extrahead %} <script type="text/javascript" src="jquery-latest.js"></script> <script type="text/javascript" src="jquery.cookie.js"></script> <script type="text/javascript" src="admin-expand.js"></script> {% endblock %}

  • admin
  • jquery
Read More

Foldable Admin Interface

Have you had a rather huge database, say 50-100+ tables? Why not compress the tables you don't want to see and expand the ones that you do want to see? This template should do the trick. It uses cookies to remember which tabs you have open and which ones you have closed. This should work on .91 to current. How to install - just CP code and save as index.html toss in your media folder under /path_to_media/template_folder/admin/index.html. next download mootools and toss this into /path_to_media/js_folder/mootools.js (alternatively you could be lazy and cp mootools into the script tag of this template) A quick and dirty fix but it sure saves time trying to find the tables you are looking for.

  • django
  • admin
  • templates
  • html
Read More

User post_save signal to auto create 'admin' profile

**How to use:** 1. puts this code at the end of the `models.py` file who haves the User Profile class declared; 2. verify if your User Profile class has the name 'UserProfile'. If not, change the code to the right name. **About:** this snippet makes the ORM create a profile each time an user is created (or updated, if the user profile lost), including 'admin' user.

  • admin
  • user
  • userprofile
Read More

Handling choices the right way

This solves the problem with **choices** described [here](http://www.b-list.org/weblog/2007/nov/02/handle-choices-right-way/) Define your choices like this (in models.py): statuses = MyChoices(BIDDING_STARTED=10, BIDDING_ENDED=20) And then: status = models.IntegerField( default=statuses.BIDDING_STARTED, choices=statuses.get_choices() )

  • models
  • admin
  • choices
Read More

admin: edit related object shortcut

Adds a shortcut to edit releated objects right/ForeignKey fields. an edit symbol will be shown right next to the "add annother" link on all select boxes, with opens the releated object currently selected in a popup window. **depends on jquery** Add this to the head of "templates/admin/base.html". you may need to add `<script type="text/javascript" src="/path/to/jquery.js"></script>` before it

  • admin
  • jquery
  • releated-objects
Read More

241 snippets posted so far.