Login

Most bookmarked snippets

Snippet List

Custom Filter using filterspecs

This snippet is based on [#1051](http://djangosnippets.org/snippets/1051/). It adds filtering by existence of at least one related object. It is an example of how to simply subclass the FilterSpec class, in order to build a custom Filter. The comment in the code contains instructions on how to implement it in a real project.

  • django
  • filterspecs
  • custom filters
Read More

Get email and push on couchdb - Model

view/admin.py ` def reactor(request): context = { 'email': read_mailbox() } return render_to_response(_lookup_template('dashboard'), context, context_instance=RequestContext(request)) ` **_Design all.js** ` function (doc) { if (doc.doc_type == 'MailArchive') { emit(doc._id, doc); } } ` **reduce.js** `_count`

  • email
  • couchdb
  • couchdbkit
Read More

Generate a dineromail form in python

This is the code we use on bandtastic.me to build a html that sends users to dineromail to pay with. This code builds a form thats ready to send multiple items.

  • django
  • python
  • dineromail
  • express checkout
Read More

get and image object

I use this snippet to save images to my imagefields on django models. This uses the very awesome requests library, so install it first pip install requests You probably want to have this be done on a celery queu, if the image is big enough.

  • imagefield
  • save file
  • save url
Read More

Horizontal RadioSelect widget

The problem with Django's default Radio button widget is that it puts the buttons in a vertical format and the documentation is somewhat silent on how to make them horizontal. If you are dealing with a long list of buttons then veritical is probably the way to go but if you are dealing with "YES/NO" situation or any other boolean choice then you will probably want them horizontal. Basically I just took the code and even the explanation from here: https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons

  • widget
  • radioselect
  • horizontal
  • radio
  • renderer
Read More

One register on admin

This code is for set one register on admin if exist more than 1 register you can not delete it or add more. Only set mymodel

  • admin
  • no-add
  • no-delete
  • one-line
  • one-row
  • one-register
Read More

"Open file in Textmate"-support in werkzeug debugger browser view

1) Install django-extensions (requires werkzeug) 2) Paste snippet into settings.py 3) manage.py runserver_plus Now you should be able to open files in textmate by clicking the file links in the werkzeug error pages. It will also take you to the correct line number and highlight files that are in your project directory in a different color.

  • debug
  • error
  • debugging
  • textmate
Read More

Coalesce for F()

Updating fields that allow for NULLs must take care about those NULLs. Use case: `Message.objects.filter(id=1).update(price=CF('price', 0) + 7)` `Message.objects.filter(id=1).update(status=CF('status') // 's')` Works for postgres. Supposedly works for mysql. Didn't test with other backends.

  • coalesce
Read More

True Unique Boolean Decorator

Useful when you want to keep only one instance of a model to be the default one. This is a decorative way of doing the same as in http://djangosnippets.org/snippets/1830/ Can this be made better as a class decorator (not having to declare explicitly the save method) ?

  • model
  • unique
  • boolean
Read More

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

django piston use origin django auth

Django-piston have two build-in authentication handlers, the HttpBasicAuthentication and OAuthAuthentication. This snippet give another choice which use the django auth. It can support ajax and normal request.

  • django
  • auth
  • piston
Read More

3110 snippets posted so far.