Login

Snippets by trubliphone

Snippet List

decorator to add GUID Field to Django Models

A decorator to add a GUID Field to a Django Model. There are other bits of code out there that do similar things, but it was important for the field to have a unique value _before_ it is saved in the database. The contribute_to_class method therefore registers the field class with the post_init signal of the class it's being added to. The handler for that signal is where field initialization is done.

  • models
  • fields
  • decorators
Read More

trubliphone has posted 1 snippet.