Django

Code

Changeset 742

Show
Ignore:
Timestamp:
09/30/05 08:49:43 (3 years ago)
Author:
jacob
Message:

Fixed #472 - added notes about File/ImageFields from the FAQ to the model API doc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/model-api.txt

    r649 r742  
    249249 
    250250    The admin represents this as an ``<input type="file">`` (a file-upload widget). 
    251  
     251     
     252    Using a `FieldField` or an ``ImageField`` (see below) in a model takes a few  
     253    steps: 
     254     
     255        1. In your settings file, you'll need to define ``MEDIA_ROOT``as the 
     256           full path to a directory where you'd like Django to store uploaded 
     257           files. (For performance, these files are not stored in the database.) 
     258           Define ``MEDIA_URL`` as the base public URL of that directory. Make 
     259           sure that this directory is writable by the Web server's user 
     260           account. 
     261         
     262        2. Add the ``FileField`` or ``ImageField`` to your model, making sure  
     263           to define the ``upload_to`` option to tell Django to which 
     264           subdirectory of ``MEDIA_ROOT`` it should upload files. 
     265 
     266        3. All that will be stored in your database is a path to the file 
     267           (relative to ``MEDIA_ROOT``). You'll must likely want to use the 
     268           convenience ``get_<fieldname>_url`` function provided by Django. For 
     269           example, if your ``ImageField`` is called ``mug_shot``, you can get 
     270           the absolute URL to your image in a template with ``{{ 
     271           object.get_mug_shot_url }}``. 
     272     
    252273    .. _`strftime formatting`: http://docs.python.org/lib/module-time.html#l2h-1941 
    253274 
     
    282303 
    283304    Requires the `Python Imaging Library`_. 
    284  
     305     
    285306    .. _Python Imaging Library: http://www.pythonware.com/products/pil/ 
    286307