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