PageRenderTime 79ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/model_forms_regress/models.py

https://code.google.com/p/mango-py/
Python | 71 lines | 52 code | 19 blank | 0 comment | 1 complexity | 5b5b316faf9f68d79860ab60bc71cf76 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import os
  2. from django.db import models
  3. from django.core.exceptions import ValidationError
  4. class Person(models.Model):
  5. name = models.CharField(max_length=100)
  6. class Triple(models.Model):
  7. left = models.IntegerField()
  8. middle = models.IntegerField()
  9. right = models.IntegerField()
  10. class Meta:
  11. unique_together = (('left', 'middle'), (u'middle', u'right'))
  12. class FilePathModel(models.Model):
  13. path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
  14. class Publication(models.Model):
  15. title = models.CharField(max_length=30)
  16. date_published = models.DateField()
  17. def __unicode__(self):
  18. return self.title
  19. class Article(models.Model):
  20. headline = models.CharField(max_length=100)
  21. publications = models.ManyToManyField(Publication)
  22. def __unicode__(self):
  23. return self.headline
  24. class CustomFileField(models.FileField):
  25. def save_form_data(self, instance, data):
  26. been_here = getattr(self, 'been_saved', False)
  27. assert not been_here, "save_form_data called more than once"
  28. setattr(self, 'been_saved', True)
  29. class CustomFF(models.Model):
  30. f = CustomFileField(upload_to='unused', blank=True)
  31. class RealPerson(models.Model):
  32. name = models.CharField(max_length=100)
  33. def clean(self):
  34. if self.name.lower() == 'anonymous':
  35. raise ValidationError("Please specify a real name.")
  36. class Author(models.Model):
  37. publication = models.OneToOneField(Publication, null=True, blank=True)
  38. full_name = models.CharField(max_length=255)
  39. class Author1(models.Model):
  40. publication = models.OneToOneField(Publication, null=False)
  41. full_name = models.CharField(max_length=255)
  42. class Homepage(models.Model):
  43. url = models.URLField(verify_exists=False)
  44. class Document(models.Model):
  45. myfile = models.FileField(upload_to='unused', blank=True)
  46. class Edition(models.Model):
  47. author = models.ForeignKey(Person)
  48. publication = models.ForeignKey(Publication)
  49. edition = models.IntegerField()
  50. isbn = models.CharField(max_length=13, unique=True)
  51. class Meta:
  52. unique_together = (('author', 'publication'), ('publication', 'edition'),)