Login

Most bookmarked snippets

Snippet List

Exists Filter OneToOneField in Admin

Adds Boolean like Filter in Admin to OneToOneField reference. Allowing to filter in the Parent for instances without Referenced Field. To register the filter, import in `urls.py` for example: import filterspecs Example `models.py`: from django.db import models class Place(models.Model): name = model.CharField(maxlength=50) address = model.CharField(maxlength=80) class Restaurant(meta.Model): place = model.OneToOneField(Place) place.exists_filter = True serves_hot_dogs = model.BooleanField() serves_pizza = model.BooleanField() Example `admin.py`: from django.contrib import admin from models import * class PlaceAdmin(admin.ModelAdmin): list_filter = ('restaurant',) admin.site.register(Place, PlaceAdmin) With this example PlaceAdmin will have a filter: By Restaurant All Yes No Where `Yes` will list `Place` with `Restaurant` instances, and `No` will list `Place` without `Restaurant` instances.

  • admin
  • filters
  • OneToOneField
Read More

Automatically create urls for templates in a directory

When developing a site, I sometimes want to be able to visually reference the HTML before it's given a real context, and a view. This extra bit of code will allow you to add a directory within your templates dir, and pull any html files and subdirectories from it. I added the if statement to automatically use an index.html file if there's no file and extension at the end. You can substitute anything you like for the "html" in "(?P<base>html)". That's just passed as an argument to prepend to the template as a base directory for the templates.

  • urls
  • templates
  • direct_to_template
Read More

Property Attributes in Memcache

Memcached Property Attributes ----------------------------- Setting the attribute will store the value in memcached; accessing the attribute will retrieve from memcached. Most useful as a way of simulating memcached "fields" on model instances. See the docstring for details.

  • cache
  • memcached
  • descriptors
Read More
Author: ori
  • 0
  • 0

Disable ordering in the admin for a model

Django admin orders models by their primary key by default, which can be undesirable on very large tables. This shows how to disable any ordering on a model. Note that this behavior is fixed in 1.4 trunk.

  • admin
  • ordering
Read More

Admin related widget wrapper with edit / delete link (widget js)

Here's the python code to produce an admin related widget with the edit and delete link also. * [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562) * [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563) * [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564) * [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)

  • admin
  • related
  • widget
  • wrapper
Read More

Admin related widget wrapper with edit / delete link (html)

Here's the python code to produce an admin related widget with the edit and delete link also. * [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562) * [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563) * [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564) * [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)

  • admin
  • related
  • widget
  • wrapper
Read More

3110 snippets posted so far.