2007-02-26 17:17:11 +00:00
|
|
|
import tempfile
|
2008-08-08 20:59:02 +00:00
|
|
|
|
|
|
|
from django.core.files.storage import FileSystemStorage
|
2011-10-13 18:51:33 +00:00
|
|
|
from django.db import models
|
2008-08-11 15:24:46 +00:00
|
|
|
from django.forms import ModelForm
|
2008-08-08 20:59:02 +00:00
|
|
|
|
2011-10-13 18:51:33 +00:00
|
|
|
|
2009-04-05 20:59:20 +00:00
|
|
|
temp_storage_dir = tempfile.mkdtemp()
|
|
|
|
temp_storage = FileSystemStorage(temp_storage_dir)
|
2007-02-26 17:17:11 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2007-02-26 17:17:11 +00:00
|
|
|
class Photo(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
title = models.CharField(max_length=30)
|
2008-08-08 20:59:02 +00:00
|
|
|
image = models.FileField(storage=temp_storage, upload_to='tests')
|
2008-08-11 15:24:46 +00:00
|
|
|
|
|
|
|
# Support code for the tests; this keeps track of how many times save()
|
|
|
|
# gets called on each instance.
|
2007-02-26 17:17:11 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2008-08-08 20:59:02 +00:00
|
|
|
super(Photo, self).__init__(*args, **kwargs)
|
|
|
|
self._savecount = 0
|
2008-08-11 15:24:46 +00:00
|
|
|
|
2008-08-28 19:28:17 +00:00
|
|
|
def save(self, force_insert=False, force_update=False):
|
|
|
|
super(Photo, self).save(force_insert, force_update)
|
2008-08-08 20:59:02 +00:00
|
|
|
self._savecount += 1
|
2008-08-11 15:24:46 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2008-08-11 15:24:46 +00:00
|
|
|
class PhotoForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Photo
|
2013-02-21 21:56:55 +00:00
|
|
|
fields = '__all__'
|