pyneric.django¶
Django extensions in a package structure similar to Django’s.
db.models.fields.pguuid¶
UUID Django fields for
PostgreSQL backends.
Loading this module patches ForeignKey so that it
can refer to an AutoPgUuidField without assuming that it is an
IntegerField.
-
class
pyneric.django.db.models.fields.pguuid.AutoPgUuidField(verbose_name=None, **kwargs)[source]¶ Bases:
django.db.models.fields.UUIDField,django.db.models.fields.AutoFieldA
UUIDFieldthat is also anAutoField.In Django 1.8, this is a real UUID field; earlier versions are supported by django-extensions’ PostgreSQLUUIDField, which stores real UUIDs, but exposes them in Python as a CharField.
The generation of the UUID value in the database must be set up manually (via a migration or another mechanism). Django 1.7 migration example:
migrations.RunSQL( "ALTER TABLE autopguuid ALTER uuid_field" " SET DEFAULT uuid_generate_v4();", "ALTER TABLE autopguuid ALTER uuid_field DROP DEFAULT;" ),
Setting the database default automatically may be added in a future version.