Login

Snippets by guettli

Snippet List

Clean Reversion History: Remove unimportant Changes

If you use this pattern to track changes in the auth user table: from django.contrib.auth.models import User from reversion.helpers import patch_admin patch_admin(User) you can't see important changes, since a version is created for every login if a user. If you want to get rid of changes which only change unimportant stuff you can use this middleware. This middleware can be used for every model. Just use this pattern in your settings: REVERSION_CLEAN={ 'django.contrib.auth': {'User': ['last_login']}, }

  • reversion
Read More

Cookie based Messages (deprecated)

DEPRECATED: Django has cookie based messages since version 1.2 This messages stores messages for the user in a cookie. I prefer this to session based messages, because the session column is a hot spot in the database if one user works with several browser tabs/windows.

  • x
Read More

Overwrite some views in settings.py

If you app defines some URLs with a name, and you want to overwrite this at project level with a different view you can use this snippet. You only need to change on line in the application code (the import statement).

  • urls
  • settings
  • reverse
Read More

urlquote() and urlencode() in one method

I think this method is handy, since you don't need to remember if you need urlquote or urlencode. It does both and adds a question mark between the path and the get parameters, if later are present. And it works around a bug in Django: MultiValueDicts (request.GET, request.POST) are handled correctly. Related: [http://code.djangoproject.com/ticket/9089](http://code.djangoproject.com/ticket/9089)

  • urlquote
  • urlencode
Read More

Timedelta Database Field

This subclass of django.models.Field stores a python datetime.timedelta object as an integer column in the database. It includes a TimedeltaFormField for editing it through djangos admin interface. Feedback welcome. 2011-04-20: TimedeltaField can now be (de)serialized. Tested with JSON. 2009-11-23: `_has_changed()` added. Before form.changed_data contained timedelta FormFields, even if nothing changed.

  • datetime
  • timedelta
  • dbfield
Read More

breadcrumbs

With this script you can create a simple breadcrumbs line for navigation: Home >> Page >> Subpage ...

  • breadcrumbs
Read More

guettli has posted 22 snippets.