Login

Snippets by guettli

Snippet List

Alter Column Lengths of Contrib Apps

If you want to modify the length of a column of a contrib application, you can either modify django (cumbersome) or you can run a post_syncdb signal hook. Related: [Ticket 4748](http://code.djangoproject.com/ticket/4748)

  • signals
Read More

Raise Exception on invalid template variable

This recipe raises an exception if there is an invalid variable in the template. See [#6766](http://code.djangoproject.com/ticket/6766) Note: I don't need this snippet any more, since I don't use the template language any more. For my projects using only python is better (complex logic, simple layout).

  • template_string_if_invalid
Read More

check if form has changed (deprecated)

This is deprecated. I don't use it anymore, since forms now have the attribute "has_changed". The method form_changed() returns a boolean value. It is True if the submitted values of the bound and valid form are different than the initial values. It works for me. Feedback welcome. Set debug=True if you want to know what's going on.

  • deprecated
Read More

lazy url reverse()

Since the decorators of your views are evaluated during parsing urls.py you have an 'chicken - egg' problem. The method reverse() can't be used since urls.py is not read. This snippets evaluates reverse() lazy. [Related ticket: 5925](http://code.djangoproject.com/ticket/5925) Django 1.4 (current trunk) has a lazy reverse.

  • decorator
  • reverse
  • lazy
Read More

HTML to POST dict converter

If you want to test a post request to a form, you need to give all input fields, even if you just want to test if one value gets changed. This snippets parses the HTML of a view and gives you a dictionary that you can give to django.test.Client.

  • testing
Read More

SQL Log Middleware + duplicates

This is based on [Snippet 161](/snippets/161/) It marks duplicated SQL queries. To avoid duplicates read: [Caching and Queryset](http://www.djangoproject.com/documentation/db-api/#caching-and-querysets) Sept. 07: Updated for current trunk: 'response' behaves like 'response.header' 22. October '07: Log into directory.

  • sql
  • middleware
  • log
  • profile
  • debug
Read More

Pass db.Field to newforms.Widget

Deprecated. I don't use this any more. Hi, I want decimal input which uses a comma as decimal seperator. It was quite complicated, but it works. It can be used as an example how to create an own subclass of an existing db.Field class and how to pass the dbfield to the widget, and use it in its render() method. I think my snippet is too complicated, but couldn't find a better solution. If you do, please tell me.

  • newforms
  • i18n
Read More

guettli has posted 22 snippets.