models.py 899 B

12345678910111213141516171819202122232425
  1. from django.db import models
  2. class Author(models.Model):
  3. first_name = models.CharField(max_length=255)
  4. last_name = models.CharField(max_length=255)
  5. dob = models.DateField()
  6. def __init__(self, *args, **kwargs):
  7. super(Author, self).__init__(*args, **kwargs)
  8. # Protect against annotations being passed to __init__ --
  9. # this'll make the test suite get angry if annotations aren't
  10. # treated differently than fields.
  11. for k in kwargs:
  12. assert k in [f.attname for f in self._meta.fields], \
  13. "Author.__init__ got an unexpected paramater: %s" % k
  14. class Book(models.Model):
  15. title = models.CharField(max_length=255)
  16. author = models.ForeignKey(Author)
  17. class Coffee(models.Model):
  18. brand = models.CharField(max_length=255, db_column="name")
  19. class Reviewer(models.Model):
  20. reviewed = models.ManyToManyField(Book)