1 | Index: docs/model-api.txt
|
---|
2 | ===================================================================
|
---|
3 | --- docs/model-api.txt (revision 5490)
|
---|
4 | +++ docs/model-api.txt (working copy)
|
---|
5 | @@ -471,8 +471,15 @@
|
---|
6 | Field options
|
---|
7 | -------------
|
---|
8 |
|
---|
9 | -The following arguments are available to all field types. All are optional.
|
---|
10 | +All field types can take a number of options. These are split into two main
|
---|
11 | +categories: those affecting how the field is represented in the database, and
|
---|
12 | +those affecting the field's display and validation.
|
---|
13 |
|
---|
14 | +Field option affecting validation are only used by components which recognise
|
---|
15 | +them, i.e. the admin interface and the form component.
|
---|
16 | +
|
---|
17 | +### Database Options
|
---|
18 | +
|
---|
19 | ``null``
|
---|
20 | ~~~~~~~~
|
---|
21 |
|
---|
22 | @@ -492,6 +499,48 @@
|
---|
23 | possible values for "no data;" Django convention is to use the empty
|
---|
24 | string, not ``NULL``.
|
---|
25 |
|
---|
26 | +``db_column``
|
---|
27 | +~~~~~~~~~~~~~
|
---|
28 | +
|
---|
29 | +The name of the database column to use for this field. If this isn't given,
|
---|
30 | +Django will use the field's name.
|
---|
31 | +
|
---|
32 | +If your database column name is an SQL reserved word, or contains
|
---|
33 | +characters that aren't allowed in Python variable names -- notably, the
|
---|
34 | +hyphen -- that's OK. Django quotes column and table names behind the
|
---|
35 | +scenes.
|
---|
36 | +
|
---|
37 | +``db_index``
|
---|
38 | +~~~~~~~~~~~~
|
---|
39 | +
|
---|
40 | +If ``True``, ``django-admin.py sqlindexes`` will output a ``CREATE INDEX``
|
---|
41 | +statement for this field.
|
---|
42 | +
|
---|
43 | +``primary_key``
|
---|
44 | +~~~~~~~~~~~~~~~
|
---|
45 | +
|
---|
46 | +If ``True``, this field is the primary key for the model.
|
---|
47 | +
|
---|
48 | +If you don't specify ``primary_key=True`` for any fields in your model,
|
---|
49 | +Django will automatically add this field::
|
---|
50 | +
|
---|
51 | + id = models.AutoField('ID', primary_key=True)
|
---|
52 | +
|
---|
53 | +Thus, you don't need to set ``primary_key=True`` on any of your fields
|
---|
54 | +unless you want to override the default primary-key behavior.
|
---|
55 | +
|
---|
56 | +``primary_key=True`` implies ``blank=False``, ``null=False`` and
|
---|
57 | +``unique=True``. Only one primary key is allowed on an object.
|
---|
58 | +
|
---|
59 | +``unique``
|
---|
60 | +~~~~~~~~~~
|
---|
61 | +
|
---|
62 | +If ``True``, this field must be unique throughout the table.
|
---|
63 | +
|
---|
64 | +This is enforced at the database level and at the Django admin-form level.
|
---|
65 | +
|
---|
66 | +### Display and Validation
|
---|
67 | +
|
---|
68 | ``blank``
|
---|
69 | ~~~~~~~~~
|
---|
70 |
|
---|
71 | @@ -569,23 +618,6 @@
|
---|
72 | Django admin site. Essentially, this means you should put ``core=True`` on all
|
---|
73 | required fields in your related object that is being edited inline.
|
---|
74 |
|
---|
75 | -``db_column``
|
---|
76 | -~~~~~~~~~~~~~
|
---|
77 | -
|
---|
78 | -The name of the database column to use for this field. If this isn't given,
|
---|
79 | -Django will use the field's name.
|
---|
80 | -
|
---|
81 | -If your database column name is an SQL reserved word, or contains
|
---|
82 | -characters that aren't allowed in Python variable names -- notably, the
|
---|
83 | -hyphen -- that's OK. Django quotes column and table names behind the
|
---|
84 | -scenes.
|
---|
85 | -
|
---|
86 | -``db_index``
|
---|
87 | -~~~~~~~~~~~~
|
---|
88 | -
|
---|
89 | -If ``True``, ``django-admin.py sqlindexes`` will output a ``CREATE INDEX``
|
---|
90 | -statement for this field.
|
---|
91 | -
|
---|
92 | ``default``
|
---|
93 | ~~~~~~~~~~~
|
---|
94 |
|
---|
95 | @@ -605,22 +637,6 @@
|
---|
96 | form. It's useful for documentation even if your object doesn't have an
|
---|
97 | admin form.
|
---|
98 |
|
---|
99 | -``primary_key``
|
---|
100 | -~~~~~~~~~~~~~~~
|
---|
101 | -
|
---|
102 | -If ``True``, this field is the primary key for the model.
|
---|
103 | -
|
---|
104 | -If you don't specify ``primary_key=True`` for any fields in your model,
|
---|
105 | -Django will automatically add this field::
|
---|
106 | -
|
---|
107 | - id = models.AutoField('ID', primary_key=True)
|
---|
108 | -
|
---|
109 | -Thus, you don't need to set ``primary_key=True`` on any of your fields
|
---|
110 | -unless you want to override the default primary-key behavior.
|
---|
111 | -
|
---|
112 | -``primary_key=True`` implies ``blank=False``, ``null=False`` and
|
---|
113 | -``unique=True``. Only one primary key is allowed on an object.
|
---|
114 | -
|
---|
115 | ``radio_admin``
|
---|
116 | ~~~~~~~~~~~~~~~
|
---|
117 |
|
---|
118 | @@ -631,13 +647,6 @@
|
---|
119 | Don't use this for a field unless it's a ``ForeignKey`` or has ``choices``
|
---|
120 | set.
|
---|
121 |
|
---|
122 | -``unique``
|
---|
123 | -~~~~~~~~~~
|
---|
124 | -
|
---|
125 | -If ``True``, this field must be unique throughout the table.
|
---|
126 | -
|
---|
127 | -This is enforced at the database level and at the Django admin-form level.
|
---|
128 | -
|
---|
129 | ``unique_for_date``
|
---|
130 | ~~~~~~~~~~~~~~~~~~~
|
---|
131 |
|
---|