models.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from __future__ import unicode_literals
  2. from django.db import models
  3. from django.utils.encoding import python_2_unicode_compatible
  4. @python_2_unicode_compatible
  5. class Place(models.Model):
  6. name = models.CharField(max_length=50)
  7. address = models.CharField(max_length=80)
  8. def __str__(self):
  9. return "%s the place" % self.name
  10. @python_2_unicode_compatible
  11. class Restaurant(models.Model):
  12. place = models.OneToOneField(Place)
  13. serves_hot_dogs = models.BooleanField(default=False)
  14. serves_pizza = models.BooleanField(default=False)
  15. def __str__(self):
  16. return "%s the restaurant" % self.place.name
  17. @python_2_unicode_compatible
  18. class Bar(models.Model):
  19. place = models.OneToOneField(Place)
  20. serves_cocktails = models.BooleanField(default=True)
  21. def __str__(self):
  22. return "%s the bar" % self.place.name
  23. class UndergroundBar(models.Model):
  24. place = models.OneToOneField(Place, null=True)
  25. serves_cocktails = models.BooleanField(default=True)
  26. @python_2_unicode_compatible
  27. class Favorites(models.Model):
  28. name = models.CharField(max_length=50)
  29. restaurants = models.ManyToManyField(Restaurant)
  30. def __str__(self):
  31. return "Favorites for %s" % self.name
  32. class Target(models.Model):
  33. pass
  34. class Pointer(models.Model):
  35. other = models.OneToOneField(Target, primary_key=True)
  36. class Pointer2(models.Model):
  37. other = models.OneToOneField(Target, related_name='second_pointer')
  38. class HiddenPointer(models.Model):
  39. target = models.OneToOneField(Target, related_name='hidden+')