models.py 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. Testing signals before/after saving and deleting.
  3. """
  4. from __future__ import unicode_literals
  5. from django.db import models
  6. from django.utils.encoding import python_2_unicode_compatible
  7. @python_2_unicode_compatible
  8. class Person(models.Model):
  9. first_name = models.CharField(max_length=20)
  10. last_name = models.CharField(max_length=20)
  11. def __str__(self):
  12. return "%s %s" % (self.first_name, self.last_name)
  13. @python_2_unicode_compatible
  14. class Car(models.Model):
  15. make = models.CharField(max_length=20)
  16. model = models.CharField(max_length=20)
  17. def __str__(self):
  18. return "%s %s" % (self.make, self.model)
  19. @python_2_unicode_compatible
  20. class Author(models.Model):
  21. name = models.CharField(max_length=20)
  22. def __str__(self):
  23. return self.name
  24. @python_2_unicode_compatible
  25. class Book(models.Model):
  26. name = models.CharField(max_length=20)
  27. authors = models.ManyToManyField(Author)
  28. def __str__(self):
  29. return self.name