PageRenderTime 36ms CodeModel.GetById 31ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/regressiontests/bug639/models.py

https://code.google.com/p/mango-py/
Python | 26 lines | 18 code | 6 blank | 2 comment | 0 complexity | b04b81e5f2b4ec025f29e73bc2b1343c MD5 | raw file
 1import tempfile
 2
 3from django.db import models
 4from django.core.files.storage import FileSystemStorage
 5from django.forms import ModelForm
 6
 7temp_storage_dir = tempfile.mkdtemp()
 8temp_storage = FileSystemStorage(temp_storage_dir)
 9
10class 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
24class PhotoForm(ModelForm):
25    class Meta:
26        model = Photo