parts/django/tests/regressiontests/bug639/models.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 import tempfile
       
     2 
       
     3 from django.db import models
       
     4 from django.core.files.storage import FileSystemStorage
       
     5 from django.forms import ModelForm
       
     6 
       
     7 temp_storage_dir = tempfile.mkdtemp()
       
     8 temp_storage = FileSystemStorage(temp_storage_dir)
       
     9 
       
    10 class Photo(models.Model):
       
    11     title = models.CharField(max_length=30)
       
    12     image = models.FileField(storage=temp_storage, upload_to='tests')
       
    13 
       
    14     # Support code for the tests; this keeps track of how many times save()
       
    15     # gets called on each instance.
       
    16     def __init__(self, *args, **kwargs):
       
    17         super(Photo, self).__init__(*args, **kwargs)
       
    18         self._savecount = 0
       
    19 
       
    20     def save(self, force_insert=False, force_update=False):
       
    21         super(Photo, self).save(force_insert, force_update)
       
    22         self._savecount += 1
       
    23 
       
    24 class PhotoForm(ModelForm):
       
    25     class Meta:
       
    26         model = Photo