Login

Tag "admin"

241 snippets

Snippet List

admin.py generator from a model

Generates admin.py file for a models.py file with the basic structure that could be edited. Usage: python gen_admin_py.py path/to/models.py creates a file admin.py in the same directory as models.py. import your models as you edit the admin.py

  • admin
Read More

showing environment variables in the django admin

Having things like DATABASE_NAME in the admin interface is handy if you're working on development and deployment systems. Replace the template admin/base_site.html with the template code. The variables to be displayed in the admin need to be exported into the environment before running the server. The python code shown is an example of a wsgi handler, and the same format can be used in manage.py for the development server.

  • admin
Read More

Fieldsets for Views

This Snippet allows a view to controle the printed forms on the templates, in a similar way to the fieldsets used by the django admin. How to Use: In the view in question, put: def some_view(request): ... fieldsets = ( (u'Title 1', {'hidden' : ('field_1', 'field_2',), 'fields' : ('field_3',)}), (u'Title 2', {'hidden' : ('field_5', 'field_6',), 'fields' : ('field_4',)}),) ) return render_to_response('some.html', {'fieldsets': fieldsets}) fieldsets = ( (None, {'hidden' : ('evento', 'colaborador',), 'fields' : ('acompanhantes',)}), ) Next, in the html just add: <form enctype="multipart/form-data" id="edit" method="post" ...> ... {% include "inc/form_snippet.html" %} ... <input type="submit" value="Submit"> </form>

  • template
  • django
  • admin
  • views
  • filters
  • python
  • tags
  • html
  • css
  • dicts
Read More
Author: Nad
  • 2
  • 0

Admin Apps Names Translation

This Snippet allows for your project's apps names to be displayed as you want in the Admin, including translations. The lists of apps and languages are created from your settings.py file. **How to use** 1st part: - Create a application called 'apps_verbose' in you project with the models.py and admin.py showed here - Create a folder inside it with named 'templatetags' with the verbose_tags.py file inside it. - Add this app to installed apps in your settings.py - If you change this app name, dont forget to correct the imports. 2nd part: - Create a folder named 'admin' in your templates folder and copy the following files form your /django/contrib/admin/templates/admin/ folder. - /app_index.html - /base.html - /change_form.html - /change_list.html - /delete_confirmation.html - /delete_selected_confirmation.html - /index.html - /object_history.html - Make the necessary changes in each file, like shown here. 3rd part: - Create translations in the Admin and enjoy.

  • template
  • django
  • admin
  • i18n
  • python
  • tags
  • html
  • app
  • translation
Read More
Author: Nad
  • 3
  • 5

Auto-create Django admin user during syncdb

This avoids the frustrating step of having to set up a new admin user every time you re-initialize your database. Put this in any `models` module. In this example I use `common.models`. Adapted from http://stackoverflow.com/questions/1466827/

  • django
  • admin
  • user
  • syncdb
  • manage
  • automatic
  • adminuser
  • admin-user
Read More

Drop in dynamic formsets in admin

A very plugable way to get Stanislaus jquery dynamic formset working in the admin with adding just one template. Add the following to templates/admin/APP/MODEL/change_form.html and also update the MODEL in the prefix setting. Thanks Stanislaus [http://elo80ka.wordpress.com/2009/10/10/jquery-plugin-django-dynamic-formset/](http://elo80ka.wordpress.com/2009/10/10/jquery-plugin-django-dynamic-formset/) [http://go2.wordpress.com/?id=725X1342&site=elo80ka.wordpress.com&url=http%3A%2F%2Fcode.google.com%2Fp%2Fdjango-dynamic-formset%2F](http://go2.wordpress.com/?id=725X1342&site=elo80ka.wordpress.com&url=http%3A%2F%2Fcode.google.com%2Fp%2Fdjango-dynamic-formset%2F) [http://www.djangosnippets.org/snippets/1389/](http://www.djangosnippets.org/snippets/1389/)

  • dynamic
  • admin
  • jquery
  • inlines
  • formsets
Read More

jstree integration to django admin

You have some tree-like structure in your models, for example: `class MyModel(models.Model): parent = models.ForeignKey('self', verbose_name=u'Parent', \ null=True, blank=True, related_name='children') name = models.CharField(u'Раздел', max_lengtch=255) position = PositiveSmallIntegerField(u'Позиция', default=0) class Meta: ordering = ('position',)` To see it as a tree in admin's object list(you also can sort items, move to another parents by drag-n-drop; and rename them) add this to admin.py: `class MyModelAdmin(admin.ModelAdmin): ordering = ('position',) list_display = ('pk','name','parent','position') raw_id_fields =('parent',) list_per_page = 900 #we sould have all objects on one page list_editable = ('name','position','parent') def parent_id(self,obj): return obj.parent and obj.parent.id or '0' class Meta: model = MyModel class Media: js = [settings.MEDIA_URL + s for s in ('lib/jquery-1.3.2.min.js', 'lib/jquery.tree.min.js', 'lib/plugins/jquery.tree.contextmenu.js', 'lib/mymodel_admin.js',)] css = { 'all':(settings.MEDIA_URL+'css/nestedsortablewidget.css',) }` mymodel_admin.js is the code listed here, if you have different title field(not "name"), change var title_column in javascript, list_display and list_editable. jstree can be obtained here: [jstree](http://www.jstree.com/) screenshot is in [my blog](http://tabed.org/blog/2010/01/06/jstree-in-django-admin/)

  • admin
  • model
  • tree
Read More

"Save and Continue" keyboard command for admin, with autoscroll

This snippet is helpful if you do a lot of editing on a single large admin form (for example, in a rich text field), and want to frequently save your progress. If you press control-S, or command-S on a Mac, the admin change form will save and reload, and the page will scroll back down to where you last were. This snippet relies on jquery, [jquery.cookie](http://plugins.jquery.com/project/cookie), and the [shortcut.js](http://www.openjs.com/scripts/events/keyboard_shortcuts/) keyboard library (which doesn't use jquery, but seemed more robust than the jquery keyboard plugins I saw). It uses a temporary cookie to remember where the page was scrolled to, to avoid having to override the admin behavior. Note: don't put this in templates/admin/change_form.html -- the circular import causes a Django crash. *Edit: Had forgotten to include jquery.cookie, which I was already including elsewhere.*

  • admin
  • jquery
  • save
Read More

Make hyperlinks for labels of raw_id_fields (jQuery)

The Django Admin site provides a "raw ID" feature for foreign keys that reference large tables. In the form view, the label of the referenced object will appear after the input. This snippet will make that label into a hyperlink that takes you to the form view for that object. To use this snippet, copy base_site.html into your templates/admin directory (if you haven't already), and paste this code into that file somewhere after the 'extends "admin/base.html"' directive. If you are already using jQuery, you can remove the first script tag. If you are already extending "extrahead", just paste the script tag(s) into the block you have created. [Documentation for raw_id_fields](http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields)

  • admin
  • jquery
  • raw_id_fields
Read More

Button Admin

This is an improvement on other ButtonAdmin implementations. A few features : It allows you to specify whether button appears on change form or change list; whether the form is to be saved before the resulting function is called; whether the button should be displayed Look at the bottom of the snippet for usage. And make sure you admin urls are enabled using (r'^admin/', include(admin.site.urls)) instead of the old method

  • admin
  • button
Read More

Dynamically create Django admin actions

With this snippet, I made a set of admin actions for assigning `Quality` objects to `Package` objects. The Django docs for [ModelAdmin.get_actions][1] explain the dictionary of tuples that is returned. [1]: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#django.contrib.admin.ModelAdmin.get_actions

  • admin
  • admin-actions
  • closures
Read More

Front end admin toolbar

This snippet will monkeypatch `django.db.models.Model` to include 7 new methods: * `get_verbose_name` Because you can't access model._meta from templates * `get_verbose_name_plural` * `get_admin_change_url` * `get_admin_delete_url` * `get_admin_history_url` * `get_admin_changelist_url` * `get_admin_add_url` This snippet also gives you the template code to paste to your `base.html` so every front end model instance view of your site will show an admin toolbar for logged in users that have admin access.

  • admin
  • toolbar
Read More

Accordion changelist admin

Allows you to hide the filters in the pages of lists of admin. Very useful when filters hide one or more columns. Add this code after the block "extrastyle"

  • admin
  • changelist
Read More

reorder apps in admin index

A quick & dirty way of sorting the apps on the admin index page however you want. It requires you to override the default admin/index.html template. The instructions are in the docstring, they assume you insert the code above in a templatetag file called admin_app_order.py

  • admin
  • reorder
Read More