============================== モデルフィールドリファレンス ============================== :revision-up-to: 17812 (1.4) unfinished .. module:: django.db.models.fields :synopsis: 組み込みフィールド型です。 .. currentmodule:: django.db.models このドキュメントは、 Django が提供している `フィールドのオプション <#common-model-field-options>`_ や `フィールド型 <#model-field-types>`_ の雑多で細かい解説です。 .. seealso:: .. If the built-in fields don't do the trick, you can try :mod:`django.contrib.localflavor`, which contains assorted pieces of code that are useful for particular countries or cultures. Also, you can easily :doc:`write your own custom model fields `. 組み込みのフィールド型で不足なことがあれば :mod:`django.contrib.localflavor` を試してみてください。これは特定の国や文化で便利に使えるコードの詰め合わせ になっています。また、 :doc:`独自のカスタムモデルフィールドの作成 ` も簡単にできます。 .. note:: 技術的には、モデルフィールドは :mod:`django.db.models.fields` モジュー ルで定義されていますが、便宜上、 :mod:`django.db.models` 内で import さ れています。モデルフィールドを使うときは、慣習的に ``from django.db import models`` として、 ``models.Field`` のよう に参照します。 .. _common-model-field-options: フィールドオプション ====================== 全てのフィールド型で、以下の引数を指定できます。これらの引数はすべてオプショ ンです。 ``null`` -------- .. attribute:: Field.null ``True`` にすると、 Django は空の値を ``NULL`` としてデータベースに入れます。 デフォルト値は ``False`` です。 空の文字列値は ``NULL`` ではなく空文字列として保存されることに注意して下さ い。 ``null=True`` が使えるのは、整数型やブール型、日付のような、文字列では ないフィールド型の場合だけです。 :attr:`~Field.null` はデータベースでの記録 操作にのみかかわるパラメタなので、フォーム上で空の値を入力できるようにした ければ ``blank=True`` も指定する必要があるでしょう (:attr:`~Field.blank` も 参照してください)。 特別な理由のない限り、 :class:`CharField` や :class:`TextField` のような、 文字列ベースのフィールドには :attr:`~Field.null` を指定しないでください。 文字列ベースのフィールドが ``null=True`` であるということは、「データがない」 ことを表すのに ``NULL`` と空文字列という二つの値が存在することを示します。 多くの場合、「データがない」ことを表すのに二つのを取り得るのは冗長でしかあ りません。 Django の慣習では、データのない文字列フィールドの値は ``NULL`` ではなく空文字列です。 .. note:: Oracle バックエンドを使っている場合、データベースの制約のため、 空文字列を許すような文字列ベースのフィールドは、 ``null=True`` オプショ ンが強制的に付加され、 ``NULL`` は空の文字列を指します。 If you want to accept :attr:`~Field.null` values with :class:`BooleanField`, use :class:`NullBooleanField` instead. ``blank`` --------- .. attribute:: Field.blank ``True`` にすると、フィールドの値を空白 (blank) にできます。デフォルト値は ``False`` です。 :attr:`~Field.null` とは違うことに注意してください。 :attr:`~Field.null` が 純粋にデータベース上の表現に関わる概念であるのに対し、 :attr:`~Field.blank` とは値の検証 (validation) に関わる概念です。あるフィールドに ``blank=True`` を指定すると、 Django の admin サイト上で、空の値のエントリを作成できます。 ``blank=False`` にすると、そのフィールドには必ず値を入れねばなりません。 .. _field-choices: ``choices`` ----------- .. attribute:: Field.choices 2 要素のタプルからなる iterable (リストまたはタプル) を、フィールドの値の選 択肢にします。 この値を指定すると、 Django の admin には標準的なテキストフィールドの代わり に選択ボックスが表示され、指定された選択肢だけをえらべます。 選択肢リストは以下のように指定します:: YEAR_IN_SCHOOL_CHOICES = ( ('FR', 'Freshman'), ('SO', 'Sophomore'), ('JR', 'Junior'), ('SR', 'Senior'), ('GR', 'Graduate'), ) 各タプルの最初の要素は、データベースに実際に保存される値です。二つ目の値は 各オプションに対する人間可読な名前です。 選択肢リストは、モデルクラスの一部として定義できます:: class Foo(models.Model): GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) また、モデルクラスの外でも定義できます:: GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) class Foo(models.Model): gender = models.CharField(max_length=1, choices=GENDER_CHOICES) また、選択肢をグループごとに集めて、名前をつけられます:: MEDIA_CHOICES = ( ('Audio', ( ('vinyl', 'Vinyl'), ('cd', 'CD'), ) ), ('Video', ( ('vhs', 'VHS Tape'), ('dvd', 'DVD'), ) ), ('unknown', 'Unknown'), ) 各タプルの最初の要素は、選択肢グループの名前です。二つ目の要素は、2 要素の タプルからなるイテレーション可能なオブジェクトです。各 2 要素タプルには、 選択肢の値と、人間可読な名前を指定します。(上の例の ``unknown`` オプション のように) グループ化されたオプションとされていないオプションを混ぜても構い ません。 :attr:`~Field.choices` セットを持つモデルフィールド各々について、 Django は 特殊なメソッドを追加し、フィールドの現在値を人間可読な形式で取得できるよう にします。データベース API ドキュメントの :meth:`~django.db.models.Model.get_FOO_display` を参照してください。 最後に、 choices はリストやタプルでなくともよく、任意の iterable オブジェク トでかまわないことに注意してください。つまり、 choices は動的生成できるので す。とはいえ、 :attr:`~Field.choices` を動的生成するようなハックをするくら いなら、適当なデータベーステーブルを :class:`ForeignKey` で参照した方がよい でしょう。というのも、 :attr:`~Field.choices` はあまり変更のない静的な選択 肢のためのオプションだからです。 ``db_column`` ------------- .. attribute:: Field.db_column フィールドに使うデータベースカラム名です。この値を指定しなければ、 Django はフィールド名を使います。 データベースカラム名が SQL の予約語であったり、 Python で変数名として使えな い文字を含んでいる (よくあるのはハイフンです) 場合でも問題ありません。 舞台裏で Django はカラム名やテーブル名をクオートします。 ``db_index`` ------------ .. attribute:: Field.db_index ``True`` にすると :djadmin:`django-admin.py sqlindexes ` を実行した時に、フィールドに対して ``CREATE INDEX`` 文を出力します。 ``db_tablespace`` ----------------- .. attribute:: Field.db_tablespace .. The name of the :doc:`database tablespace ` to use for this field's index, if this field is indexed. The default is the project's :setting:`DEFAULT_INDEX_TABLESPACE` setting, if set, or the :attr:`~Options.db_tablespace` of the model, if any. If the backend doesn't support tablespaces for indexes, this option is ignored. フィールドをインデクス化する場合に、このインデクスを格納する :doc:`データベースのテーブルスペース ` の名前です。デフォルトの値は、プロジェクトで設定されている :setting:`DEFAULT_INDEX_TABLESPACE` です。この値がなければ、モデルの :attr:`~Options.db_tablespace` を使います。データベースバックエンドが インデクス格納用テーブルスペースをサポートしていない場合、 このオプションは無視されます。 ``default`` ----------- .. attribute:: Field.default フィールドのデフォルト値です。この値は、何らかの値でも、呼び出し可能オブジェ クトでもかまいません。呼び出し可能オブジェクトの場合、新たなオブジェクトが 生成されるたびに呼び出されます。 ``editable`` ------------ .. attribute:: Field.editable ``False`` にすると、 admin 上や、モデルクラスから生成したフォームの上でフィー ルドの値を編集できなくなります。デフォルト値は ``True`` です。 ``error_messages`` ------------------ .. versionadded:: 1.2 .. attribute:: Field.error_messages The ``error_messages`` argument lets you override the default messages that the field will raise. Pass in a dictionary with keys matching the error messages you want to override. Error message keys include ``null``, ``blank``, ``invalid``, ``invalid_choice``, and ``unique``. Additional error message keys are specified for each field in the `Field types`_ section below. ``help_text`` ------------- .. attribute:: Field.help_text オブジェクトの admin フォームの下に表示される、追加の「ヘルプ」テキストです。 とはいえ、オブジェクトが admin のフォームを持っていなくてもドキュメントとし て有用でしょう。 この値は admin インタフェース上に表示されるときに HTML エスケープされ *ない* ので注意してください。必要ならば、下記の例のように :attr:`~Field.help_text` に HTML を含めてもかまいません:: help_text="Please use the following format: YYYY-MM-DD." プレーンテキストを使って、 ``django.utils.html.escape()`` でHTML の特殊文字 をエスケープしてもかまいません。 ``primary_key`` --------------- .. attribute:: Field.primary_key ``True`` に指定すると、フィールドをモデルの主キーにします。 モデルのどのフィールドにも ``primary_key=True`` を指定しなければ、Django は 自動的に :class:`IntegerField` を追加して主キーを保存します。従って、デフォ ルトの主キーの振舞いを変更したいのでないかぎり、 ``primary_key=True`` をフィー ルドに指定しておく必要はありません。詳しくは :ref:`automatic-primary-key-fields` を参照してください。 ``primary_key=True`` であるということは、 :attr:`null=False ` かつ :attr:`unique=True ` であることを指します。一つのオブジェ クトには一つしか主キーを指定できません。 ``unique`` ---------- .. attribute:: Field.unique ``True`` であれば、フィールドはテーブル全体で一意の値を取らねばなりません。 この制約は、データベースレベルと Django の admin のレベルで適用されます。 重複した値を持つ :attr:`~Field.unique` フィールドを含んだモデルを保存しよう とすると、モデルの :meth:`~django.db.models.Model.save` メソッドによって :exc:`django.db.IntegrityError` が送出されます。 このオプションは、 :class:`ManyToManyField` 以外の全てのフィールドで利用で きます。 ``unique_for_date`` ------------------- .. attribute:: Field.unique_for_date :class:`DateField` や :class:`DateTimeField` 型のフィールドの名前を指定して おくと、そのフィールドの日付に対して一意な値になるように制約します。 例えば、 ``title`` という名前のフィールドがあり、 ``unique_for_date="pub_date"`` が指定されていたとすると、 Django は同じ ``title`` や ``pub_date`` の値を持つようなエントリを受け入れません。 この制約は Django の admin フォームのレベルで適用され、データベースレベルで は適用されません。 ``unique_for_month`` -------------------- .. attribute:: Field.unique_for_month :attr:`~Field.unique_for_date` と同様ですが、フィールドの値が月ごとに一意で あるように制約します。 ``unique_for_year`` ------------------- .. attribute:: Field.unique_for_year :attr:`~Field.unique_for_date` や :attr:`~Field.unique_for_month` と同じで す。 ``verbose_name`` ------------------- .. attribute:: Field.verbose_name A human-readable name for the field. If the verbose name isn't given, Django will automatically create it using the field's attribute name, converting underscores to spaces. See :ref:`Verbose field names `. ``validators`` ------------------- .. versionadded:: 1.2 .. attribute:: Field.validators A list of validators to run for this field. See the :doc:`validators documentation ` for more information. .. _model-field-types: フィールド型 ============= .. currentmodule:: django.db.models ``AutoField`` ------------- .. class:: AutoField(**options) :class:`IntegerField` の一種で、利用可能な ID の中から自動的にインクリメン トしていきます。通常、このフィールドが直接必要になることはないでしょう。主 キーのフィールドは、特に指定しない限り自動的に追加されます。 :ref:`automatic-primary-key-fields` を参照してください。 ``BigIntegerField`` ------------------- .. versionadded:: 1.2 .. class:: BigIntegerField([**options]) A 64 bit integer, much like an :class:`IntegerField` except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The admin represents this as an ```` (a single-line input). ``BooleanField`` ---------------- .. class:: BooleanField(**options) 真偽 (true/false) 値を表すフィールドです。 admin ではこのフィールドはチェックボックスとして表現されます。 If you need to accept :attr:`~Field.null` values then use :class:`NullBooleanField` instead. .. versionchanged:: 1.2 In previous versions of Django when running under MySQL ``BooleanFields`` would return their data as ``ints``, instead of true ``bools``. See the release notes for a complete description of the change. ``CharField`` ------------- .. class:: CharField(max_length=None, [**options]) 文字列フィールドで、短い文字列からやや長いものに適しています。 大量のテキストを入れたい場合には :class:`~django.db.models.TextField` を使っ て下さい。 admin では ```` (一行の入力フィールド) で表現されます。 :class:`CharField` 必須の引数があります: .. attribute:: CharField.max_length フィールドの (文字数で表した) 最大長です。 ``max_length`` への制約はデー タベースと Django 内の検証の両方のレベルで行われます。 .. note:: If you are writing an application that must be portable to multiple database backends, you should be aware that there are restrictions on ``max_length`` for some backends. Refer to the :doc:`database backend notes ` for details. .. admonition:: MySQL ユーザへの注意 MySQLdb 1.2.2 でこのフィールドを使っていて、コレーションを (デフォルト 設定 *でない*) ``utf8_bin`` に設定していると、いろいろと問題を引き起こ します。詳しくは :ref:`MySQL データベースに関する注意 ` を参照してください。 ``CommaSeparatedIntegerField`` ------------------------------ .. class:: CommaSeparatedIntegerField(max_length=None, [**options]) カンマで区切った整数からなるフィールドです。 :class:`CharField` と同じく、 :attr:`~CharField.max_length` 引数が必要です。 ``DateField`` ------------- .. class:: DateField([auto_now=False, auto_now_add=False, **options]) 日付フィールドです。オプションの引数がいくつかあります: .. attribute:: DateField.auto_now オブジェクトを保存する度に、その時の時刻を自動的に設定します。 "last-modified" タイムスタンプの実現に便利です。この値はオーバライドで きるデフォルト値ではなく、 *常に* 現在の日付になるので注意してください。 .. attribute:: DateField.auto_now_add オブジェクトを生成した時の時刻を自動的に設定します。タイムスタンプの生 成に便利です。この値はオーバライドできるデフォルト値ではなく、 *常に* 現在の日付になるので注意してください。 .. The admin represents this as an ```` with a JavaScript calendar, and a shortcut for "Today". Includes an additional ``invalid_date`` error message key. admin では、 JavaScript のカレンダーと 「今日」へのショートカットのついた ```` として表現されます。追加エラーメッセージのキー ``invalid_date`` を含みます。 .. note:: As currently implemented, setting ``auto_now`` or ``auto_now_add`` to ``True`` will cause the field to have ``editable=False`` and ``blank=True`` set. ``DateTimeField`` ----------------- .. class:: DateTimeField([auto_now=False, auto_now_add=False, **options]) 日付と時刻のフィールドです。 :class:`DateField` と同じオプションを取ります。 admin では JavaScript のショートカットのついた ```` フィールドで表現されます。 ``DecimalField`` ---------------- .. class:: DecimalField(max_digits=None, decimal_places=None, [**options]) 固定精度の 10 進小数です。 Python の :class:`~deciaml.Decimal` 型インスタン スとして表現されます。 **必須の** 引数が 2 つあります: .. attribute:: DecimalField.max_digits .. The maximum number of digits allowed in the number. Note that this number must be greater than or equal to ``decimal_places``, if it exists. 値を表現するのに使える最大桁数です。なお ``decimal_places`` が指定された場合、それ以上の値である必要があります。 .. attribute:: DecimalField.decimal_places 小数部の保存に使われる桁数です。 例えば、小数部が 2 桁で、 999 までの数を表現できるようなフィールドを作成す るには、以下のようにします:: models.DecimalField(..., max_digits=5, decimal_places=2) 小数部の精度が 10 桁で、 10 億までの数を表現できるようにしたければ、以下の ようにします:: models.DecimalField(..., max_digits=19, decimal_places=10) admin では、 ```` (一行のテキスト入力) で表現されます。 .. note:: For more information about the differences between the :class:`FloatField` and :class:`DecimalField` classes, please see :ref:`FloatField vs. DecimalField `. ``EmailField`` -------------- .. class:: EmailField([max_length=75, **options]) 値が有効なメールアドレスであることをチェックする :class:`CharField` です。 ``FileField`` ------------- .. class:: FileField(upload_to=None, [max_length=100, **options]) ファイルアップロードのためのフィールドです。 .. note:: The ``primary_key`` and ``unique`` arguments are not supported, and will raise a ``TypeError`` if used. **必須の** 引数を一つ持ちます: .. attribute:: FileField.upload_to ローカルのファイルシステム上のパスです。このパスは :setting:`MEDIA_ROOT` に設定したパスの後ろにつけられ、 :attr:`~django.core.files.File.url` 属性の値を決める際に使われます。 This path may contain :func:`~time.strftime` formatting, which will be replaced by the date/time of the file upload (so that uploaded files don't fill up the given directory). ``upload_to`` には、関数のような呼び出し可能オブジェクトも指定できます。 呼び出し可能オブジェクトを指定すると、ファイル名を含むアップロードパス を決めるために呼び出されます。この呼び出し可能オブジェクトを定義する場 合、二つの引数をとり、 (スラッシュで始まる) Unix 形式のパスを返さねば なりません。返したパスはストレージシステムで使われます。二つの引数の説 明を以下に示します: ====================== =============================================== 引数 説明 ====================== =============================================== ``instance`` ``FileField`` を定義しているモデルのインス タンスです。もっと正確には、ファイルを添付 しようとしているインスタンスです。ほとんど の場合、このオブジェクトはまだデータベース に保存されていないので、デフォルトの ``AutoField`` を使っている場合、 *まだ主キーフィールドの値が決まっていない* ことがあります。 ``filename`` もともとファイルに付けられていたファイル名 です。最終的なファイルの保存パスを決めると きに考慮してもよいですし、しなくてもかまい ません。 ====================== =============================================== また、オプションの引数を一つとります: .. attribute:: FileField.storage 省略可能です。ストレージの操作と、ファイルの取得を行うストレージ オブジェクトです。このオブジェクトの作り方については、 :doc:`/topics/files` を参照してください。 admin では、 ```` (ファイルアップロードウィジェット) で表現されます。 モデル中で :class:`FileField` や :class:`ImageField` (下記参照) を使うには、 以下のようなステップが必要です: 1. Django にアップロードされたファイルを保存させたい場所のフルパスを設 定ファイル中の :setting:`MEDIA_ROOT` に指定します。(パフォーマンス上 の理由から、アップロードされたファイルはデータベースに保存されませ ん。) 保存場所への公開 URL を :setting:`MEDIA_URL` に指定します。 ディレクトリが Web サーバのユーザアカウントによって書き込み可能であ るか確認してください。 2. :class:`FileField` や :class:`ImageField` をモデルに定義します。この とき、 :attr:`~FileField.upload_to` オプションを指定して、 :setting:`MEDIA_ROOT` 下のサブディレクトリのどこにアップロードされた ファイルを置くべきかを Django に教えます。 3. データベースに保存されるのはファイルへのパス (:setting:`MEDIA_ROOT` からの相対) です。Django の提供している :attr:`~django.core.files.File.url` を使うことになるでしょう。例えば、 ``mug_shot`` という名前の :class:`ImageField` があれば、画像への絶対 パスは ``{{ object.get_mug_shot_url }}`` で取得できます。 .. For example, say your :setting:`MEDIA_ROOT` is set to ``'/home/media'``, and :attr:`~FileField.upload_to` is set to ``'photos/%Y/%m/%d'``. The ``'%Y/%m/%d'`` part of :attr:`~FileField.upload_to` is :func:`~time.strftime` formatting; ``'%Y'`` is the four-digit year, ``'%m'`` is the two-digit month and ``'%d'`` is the two-digit day. If you upload a file on Jan. 15, 2007, it will be saved in the directory ``/home/media/photos/2007/01/15``. 例えば、 :setting:`MEDIA_ROOT` を ``'/home/media'`` にして、 :attr:`~FileField.upload_to` を ``'photos/%Y/%m/%d'`` に設定したとします。 ``upload_to`` の ``'%Y/%m/%d'`` の部分は :func:`~time.strftime` と同じ フォーマット文字を使っています。すなわち、 ``'%Y'`` が 4 桁の年号、 ``'%m'`` が 2 桁の月、 ``'%d'`` が 2 桁の日を表します。従って、ファイルを 2007 年の 1 月 15 日にアップロードすると、 ``/home/media/photos/2007/01/15`` に保存されます。 .. If you wanted to retrieve the uploaded file's on-disk filename, or the file's size, you could use the :attr:`~django.core.files.File.name` and :attr:`~django.core.files.File.size` attributes respectively; for more information on the available attributes and methods, see the :class:`~django.core.files.File` class reference and the :doc:`/topics/files` topic guide. アップロードファイルのディスク上でのファイル名またはサイズを知りたい場合は、 それぞれ :attr:`~django.core.files.File.name`, :attr:`~django.core.files.File.size` 属性を使えます。利用可能な属性やメソッドの 詳細については :class:`~django.core.files.File` クラスのリファレンスと :doc:`/topics/files` を参照してください。 .. note:: The file is saved as part of saving the model in the database, so the actual file name used on disk cannot be relied on until after the model has been saved. The uploaded file's relative URL can be obtained using the :attr:`~django.db.models.fields.FileField.url` attribute. Internally, this calls the :meth:`~django.core.files.storage.Storage.url` method of the underlying :class:`~django.core.files.storage.Storage` class. .. _file-upload-security: ファイルのアップロードを処理するときには、常にアップロード先の場所やアップ ロードされるファイルに注意して、セキュリティホールを避けるようにしてくださ い。 *アップロードされる全てのファイルをチェックして* 、予想外のファイルが アップロードされないようにしましょう。例えば、バリデーションを行わずに Web サーバのドキュメントルート下へのファイルのアップロードを盲目的に受け入れる と、そこに誰かが CGI や PHP スクリプトをアップロードして、あなたのサイト上 の URL を訪問した人にスクリプトを実行させられてしまいます。そんなことを許し てはなりません。 Also note that even an uploaded HTML file, since it can be executed by the browser (though not by the server), can pose security threats that are equivalent to XSS or CSRF attacks. デフォルトでは、 :class:`FileField` インスタンスは ``varchar(100)`` カラム をデータベースに作成します。他のフィールドと同様、 :attr:`~CharField.max_length` 引数を使って最大長を変更できます。 FileField and FieldFile ~~~~~~~~~~~~~~~~~~~~~~~ When you access a :class:`FileField` on a model, you are given an instance of :class:`FieldFile` as a proxy for accessing the underlying file. This class has several methods that can be used to interact with file data: .. method:: FieldFile.open(mode='rb') Behaves like the standard Python ``open()`` method and opens the file associated with this instance in the mode specified by ``mode``. .. method:: FieldFile.close() Behaves like the standard Python ``file.close()`` method and closes the file associated with this instance. .. method:: FieldFile.save(name, content, save=True) This method takes a filename and file contents and passes them to the storage class for the field, then associates the stored file with the model field. If you want to manually associate file data with :class:`FileField` instances on your model, the ``save()`` method is used to persist that file data. Takes two required arguments: ``name`` which is the name of the file, and ``content`` which is an object containing the file's contents. The optional ``save`` argument controls whether or not the instance is saved after the file has been altered. Defaults to ``True``. Note that the ``content`` argument should be an instance of :class:`django.core.files.File`, not Python's built-in file object. You can construct a :class:`~django.core.files.File` from an existing Python file object like this:: from django.core.files import File # Open an existing file using Python's built-in open() f = open('/tmp/hello.world') myfile = File(f) Or you can construct one from a Python string like this:: from django.core.files.base import ContentFile myfile = ContentFile("hello world") For more information, see :doc:`/topics/files`. .. method:: FieldFile.delete(save=True) Deletes the file associated with this instance and clears all attributes on the field. Note: This method will close the file if it happens to be open when ``delete()`` is called. The optional ``save`` argument controls whether or not the instance is saved after the file has been deleted. Defaults to ``True``. ``FilePathField`` ----------------- .. class:: FilePathField(path=None, [match=None, recursive=False, max_length=100, **options]) ファイルシステム上のあるディレクトリ下のファイル名だけを選べるようになって いる :class:`CharField` です。 3 つの特別な引数があり、そのうち最初の一つは **必須** です: .. attribute:: FilePathField.path 必須です。 :class:`FilePathField` が選択肢を作成するためのディレクトリ への絶対パスです。例: ``"/home/images"`` .. attribute:: FilePathField.match オプションです。正規表現を表す文字列で、 :class:`FilePathField` がファ イル名のフィルタに使います。正規表現はフルパスではなくファイル名に適用 されるので注意してください。 例: ``"foo.*\.txt$"`` は ``foo23.txt`` に はマッチしますが、 ``bar.txt`` や ``foo23.gif`` にはマッチしません。 .. attribute:: FilePathField.recursive オプションです。 ``True`` または ``False`` です。デフォルトは ``False`` で、 :attr:`~FilePathField.path` のサブディレクトリを含めるかどうかを指 定します。 もちろん、これらの引数を組み合わせて使ってもかまいません。 よくある勘違いは、 :attr:`~FilePathField.match` がファイル名ではなくフルパ スに適用されると思ってしまうことです。以下の例:: FilePathField(path="/home/images", match="foo.*", recursive=True) は ``/home/images/foo.gif`` にはマッチしますが、ファイル名本体 (``foo.gif`` や ``bar.gif``) にマッチするため、 ``/home/images/foo/bar.gif`` にはマッチ しません。 :class:`FilePathField` インスタンスは ``varchar(100)`` カラムをデータベース に作成します。他のフィールドと同様、 :attr:`~CharField.max_length` 引数を使っ て最大長を変更できます。 ``FloatField`` -------------- .. class:: FloatField([**options]) 浮動小数点数です。Python の ``float`` 型インスタンスで表現されます。 admin では、 ```` (一行の入力フィールド) で表現されます。 .. _floatfield_vs_decimalfield: .. admonition:: ``FloatField`` vs. ``DecimalField`` The :class:`FloatField` class is sometimes mixed up with the :class:`DecimalField` class. Although they both represent real numbers, they represent those numbers differently. ``FloatField`` uses Python's ``float`` type internally, while ``DecimalField`` uses Python's ``Decimal`` type. For information on the difference between the two, see Python's documentation for the :mod:`decimal` module. ``ImageField`` -------------- .. class:: ImageField(upload_to=None, [height_field=None, width_field=None, max_length=100, **options]) .. Inherits all attributes and methods from :class:`FileField`, but also validates that the uploaded object is a valid image. :class:`FileField` の属性とメソッドをすべて継承し、さらにアップロードされた オブジェクトが有効なイメージかどうか検証します。 In addition to the special attributes that are available for :class:`FileField`, an :class:`ImageField` also has :attr:`~django.core.files.File.height` and :attr:`~django.core.files.File.width` attributes. To facilitate querying on those attributes, :class:`ImageField` has two extra optional arguments: .. attribute:: ImageField.height_field モデルインスタンスを保存する際に画像の高さを自動的に入れたいモデルフィー ルドの名前です。 .. attribute:: ImageField.width_field モデルインスタンスを保存する際に画像の幅を自動的に入れたいモデルフィー ルドの名前です。 `Python Imaging Library`_ が必要です。 .. _Python Imaging Library: http://www.pythonware.com/products/pil/ :class:`ImageField` インスタンスは ``varchar(100)`` カラムをデータベースに 作成します。他のフィールドと同様、 :attr:`~CharField.max_length` 引数を使っ て最大長を変更できます。 ``IntegerField`` ---------------- .. class:: IntegerField([**options]) 整数です。 admin では、 ```` (一行の入力フィールド) で表 現されます。 ``IPAddressField`` ------------------ .. class:: IPAddressField([**options]) IP アドレスを文字列形式で表したもの (例: "192.0.2.30") です。admin では、 ```` (一行の入力フィールド) で表現されます。 ``GenericIPAddressField`` ------------------------- .. class:: GenericIPAddressField([protocol=both, unpack_ipv4=False, **options]) .. versionadded:: 1.4 An IPv4 or IPv6 address, in string format (e.g. ``192.0.2.30`` or ``2a02:42fe::4``). The admin represents this as an ```` (a single-line input). The IPv6 address normalization follows :rfc:`4291#section-2.2` section 2.2, including using the IPv4 format suggested in paragraph 3 of that section, like ``::ffff:192.0.2.0``. For example, ``2001:0::0:01`` would be normalized to ``2001::1``, and ``::ffff:0a0a:0a0a`` to ``::ffff:10.10.10.10``. All characters are converted to lowercase. .. attribute:: GenericIPAddressField.protocol Limits valid inputs to the specified protocol. Accepted values are ``'both'`` (default), ``'IPv4'`` or ``'IPv6'``. Matching is case insensitive. .. attribute:: GenericIPAddressField.unpack_ipv4 Unpacks IPv4 mapped addresses like ``::ffff::192.0.2.1``. If this option is enabled that address would be unpacked to ``192.0.2.1``. Default is disabled. Can only be used when ``protocol`` is set to ``'both'``. ``NullBooleanField`` -------------------- .. class:: NullBooleanField([**options]) :class:`BooleanField` と同じですが、 ``NULL`` を選択肢に使えます。 ``null=True`` の :class:`BooleanField` の代わりに使って下さい。 admin では、 「不明」 ("Unknown") 「はい」 ("Yes")、「いいえ」 ("No") の選択肢をもつ ``