mirror of
https://github.com/django/django.git
synced 2025-12-15 21:45:20 +00:00
Fixed #19463 -- Added UUIDField
Uses native support in postgres, and char(32) on other backends.
This commit is contained in:
parent
0d1561d197
commit
ed7821231b
17 changed files with 274 additions and 4 deletions
|
|
@ -1012,6 +1012,31 @@ Like all :class:`CharField` subclasses, :class:`URLField` takes the optional
|
|||
:attr:`~CharField.max_length` argument. If you don't specify
|
||||
:attr:`~CharField.max_length`, a default of 200 is used.
|
||||
|
||||
UUIDField
|
||||
---------
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
.. class:: UUIDField([**options])
|
||||
|
||||
A field for storing universally unique identifiers. Uses Python's
|
||||
:class:`~python:uuid.UUID` class. When used on PostgreSQL, this stores in a
|
||||
``uuid`` datatype, otherwise in a ``char(32)``.
|
||||
|
||||
Universally unique identifiers are a good alternative to :class:`AutoField` for
|
||||
:attr:`~Field.primary_key`. The database will not generate the UUID for you, so
|
||||
it is recommended to use :attr:`~Field.default`::
|
||||
|
||||
import uuid
|
||||
from django.db import models
|
||||
|
||||
class MyUUIDModel(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
# other fields
|
||||
|
||||
Note that a callable (with the parentheses omitted) is passed to ``default``,
|
||||
not an instance of ``UUID``.
|
||||
|
||||
Relationship fields
|
||||
===================
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue