Login

Snippets by jdriscoll

Snippet List

Convert CamelCase to lowercase_with_underscores

Just a simple regex function to convert a camel case string ("ClassName") to a lower case string with underscores ("class_name"). Came across a need for this when I was trying to add properties to a model at runtime using `object.__class__.__name__`. This is a modification of the function "get_verbose_name" found in django.db.models.options.

  • utilities
  • formatting
  • one-liners
Read More

"Link To" helper tag

Simple template tag that assumes some common conventions in order to quickly get a link to a specific model instance.

  • template
  • models
  • links
  • tags
  • anchors
Read More

Natural language date/time form fields

Form fields use the dateutil module [http://labix.org/python-dateutil](http://labix.org/python-dateutil) to parse natural-language input for date and datetime fields. The callback function will replace all date and datetime fields automatically for form_for_model and form_for_instance. **Note**: by replacing the 'form_class' keyword argument instead of just returning the field itself you preserve the 'required' status of the field.

  • newforms
  • datetime
  • date
Read More

jdriscoll has posted 4 snippets.