PageRenderTime 162ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. import tempfile
  2. from django.db import models
  3. from django.core.files.storage import FileSystemStorage
  4. from django.forms import ModelForm
  5. temp_storage_dir = tempfile.mkdtemp()
  6. temp_storage = FileSystemStorage(temp_storage_dir)
  7. class Photo(models.Model):
  8. title = models.CharField(max_length=30)
  9. image = models.FileField(storage=temp_storage, upload_to='tests')
  10. # Support code for the tests; this keeps track of how many times save()
  11. # gets called on each instance.
  12. def __init__(self, *args, **kwargs):
  13. super(Photo, self).__init__(*args, **kwargs)
  14. self._savecount = 0
  15. def save(self, force_insert=False, force_update=False):
  16. super(Photo, self).save(force_insert, force_update)
  17. self._savecount += 1
  18. class PhotoForm(ModelForm):
  19. class Meta:
  20. model = Photo