Login

Snippets by SmileyChris

Snippet List

Show users' full names for foreign keys in admin

This is a ModelAdmin base class you can use to make foreign key references to User a bit nicer in admin. In addition to showing a user's username, it also shows their full name too (if they have one and it differs from the username). **2009-08-14**: updated to handle many to many fields and easily configure whether to always show the username (if it differs from full name)

  • user
  • modeladmin
  • get_full_name
Read More

Gzip decorator

Rather than using the full GZipMiddleware, you may want to just compress some views. This decorator lets you do that. @gzip_compress def your_view(request, ...): ....

  • middleware
  • decorator
  • gzip
Read More

"an" filter

A template filter which returns "a" or "an" depending on the phonetic value of given text.

  • template-filter
  • grammar
Read More

TestCase base class to easily temporarily change module values

1. Base your test case off `ModuleTestCase` and set a class attribute containing a dictionary of modules which you want to be able to revert the values of. 2. Use `self.modulename.attribute = something` in your `setUp` method or test cases to change the module's attribute values. 3. The values will be automatically restored when each test case finishes. For the common case of reverting the settings module, just use the `SettingsTestCase` as your base class.

  • tests
Read More