mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +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
|
@ -92,7 +92,8 @@ below for information on how to set up your database correctly.
|
|||
PostgreSQL notes
|
||||
================
|
||||
|
||||
Django supports PostgreSQL 9.0 and higher.
|
||||
Django supports PostgreSQL 9.0 and higher. It requires the use of Psycopg2
|
||||
2.0.9 or higher.
|
||||
|
||||
PostgreSQL connection settings
|
||||
-------------------------------
|
||||
|
|
|
@ -888,6 +888,20 @@ For each field, we describe the default widget used if you don't specify
|
|||
|
||||
These are the same as ``CharField.max_length`` and ``CharField.min_length``.
|
||||
|
||||
``UUIDField``
|
||||
-------------
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
.. class:: UUIDField(**kwargs)
|
||||
|
||||
* Default widget: :class:`TextInput`
|
||||
* Empty value: ``''`` (an empty string)
|
||||
* Normalizes to: A :class:`~python:uuid.UUID` object.
|
||||
* Error message keys: ``required``, ``invalid``
|
||||
|
||||
This field will accept any string format accepted as the ``hex`` argument
|
||||
to the :class:`~python:uuid.UUID` constructor.
|
||||
|
||||
Slightly complex built-in ``Field`` classes
|
||||
-------------------------------------------
|
||||
|
|
|
@ -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