2
0

models.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. class Animal(models.Model):
  4. name = models.CharField(max_length=150)
  5. latin_name = models.CharField(max_length=150)
  6. def __unicode__(self):
  7. return self.common_name
  8. class Plant(models.Model):
  9. name = models.CharField(max_length=150)
  10. class Meta:
  11. # For testing when upper case letter in app name; regression for #4057
  12. db_table = "Fixtures_regress_plant"
  13. class Stuff(models.Model):
  14. name = models.CharField(max_length=20, null=True)
  15. owner = models.ForeignKey(User, null=True)
  16. def __unicode__(self):
  17. return unicode(self.name) + u' is owned by ' + unicode(self.owner)
  18. __test__ = {'API_TESTS':"""
  19. >>> from django.core import management
  20. # Load a fixture that uses PK=1
  21. >>> management.call_command('loaddata', 'sequence', verbosity=0)
  22. # Create a new animal. Without a sequence reset, this new object
  23. # will take a PK of 1 (on Postgres), and the save will fail.
  24. # This is a regression test for ticket #3790.
  25. >>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus')
  26. >>> animal.save()
  27. ###############################################
  28. # Regression test for ticket #4558 -- pretty printing of XML fixtures
  29. # doesn't affect parsing of None values.
  30. # Load a pretty-printed XML fixture with Nulls.
  31. >>> management.call_command('loaddata', 'pretty.xml', verbosity=0)
  32. >>> Stuff.objects.all()
  33. [<Stuff: None is owned by None>]
  34. """}