Login

Tag "uuid"

Snippet List

Add custom fields to the built-in Group model

Add fields and extend Django's built-in `Group` model using a `OneToOneField` (i.e. a profile model). In this example, we add a `UUIDField`. Whenever a new group is created, we automatically (via signals) create a corresponding `Role` record referencing the newly created group. Whenever a Group is deleted, the corresponding Role is deleted as well.

  • model
  • group
  • uuid
  • signals
Read More

autogenerated UUID model field

Provides UUIDField for your models. This version creates very short UUID represenation (21 chars) when the record is added eg. in admin. Generated ids are safe to be used in URLs. You can put represent it in admin as 'readonly_fields=("uuid",)'

  • model
  • field
  • uuid
Read More

Arbitrary auto-generated primary keys

Auto-incremented primary keys are the default in Django and they are supported natively in most databases but for anything more complex things are less trivial. DB sequences are not standard, may not be available and even if they are, they are typically limited to simple integer sequence generators. This snippet bypasses the problem by allowing arbitrary auto-generated keys in Python. The implementation needs to determine whether an IntegrityError was raised because of a duplicate primary key. Unfortunately this information is not readily available, it can be found only by sniffing the DB-specific error code and string. The current version works for MySQL (5.1 at least); comments about how to determine this in other databases will be incorporated in the snippet.

  • mysql
  • sequence
  • uuid
  • auto decrement
  • auto increment
  • primary key
Read More

UUIDField oriented django User

This code monkey-patches the default User model to rather use a primary key of UUIDField (see http://www.djangosnippets.org/snippets/1496/). This code also makes the email field required. This code is wildly dangerous, not completely future proof, and probably not advisable to use. If you do wish to use it, it will be easiest to implement on a fresh db with a syncdb. If you need to migrate existing user data the onus is on you to figure out an appropriate db migration plan. I placed this code in a models.py, but it is probably more reliably placed in urls.py

  • user
  • auth
  • uuid
  • monkeypatch
Read More

UUIDField

This snippet provides a uuid field for models, improving on the work in http://www.djangosnippets.org/snippets/335/

  • model
  • field
  • uuid
Read More

uuid model field

This code provides a primary key field that is globally unique. It uses the pre_save method to auto-populate the field with a Universal Unique Id as the record is saved the first time.

  • model
  • field
  • uuid
  • universally-unique-identifier
Read More

UUIDField

UUIDField is a field which stores an uuid generated by pythons new uuid module. it's included with the python 2.5 distribution by default, but if you run an older version of python you can happily copy the file from 2.5 to django/utils/uuid.py or your project directory.

  • fields
  • field
  • uuid
Read More

8 snippets posted so far.