|
@@ -33,6 +33,7 @@ store a photo::
|
|
|
name = models.CharField(max_length=255)
|
|
|
price = models.DecimalField(max_digits=5, decimal_places=2)
|
|
|
photo = models.ImageField(upload_to='cars')
|
|
|
+ specs = models.FileFile(upload_to='specs')
|
|
|
|
|
|
Any ``Car`` instance will have a ``photo`` attribute that you can use to get at
|
|
|
the details of the attached photo::
|
|
@@ -73,6 +74,16 @@ location (:setting:`MEDIA_ROOT` if you are using the default
|
|
|
>>> car.photo.path == new_path
|
|
|
True
|
|
|
|
|
|
+To save an existing file on disk to a :class:`~django.db.models.FileField`::
|
|
|
+
|
|
|
+ >>> from pathlib import Path
|
|
|
+ >>> from django.core.files import File
|
|
|
+ >>> path = Path('/some/external/specs.pdf')
|
|
|
+ >>> car = Car.objects.get(name='57 Chevy')
|
|
|
+ >>> with path.open(mode='rb') as f:
|
|
|
+ ... car.specs = File(f, name=path.name)
|
|
|
+ ... car.save()
|
|
|
+
|
|
|
.. note::
|
|
|
|
|
|
While :class:`~django.db.models.ImageField` non-image data attributes, such
|