models.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. Tests for F() query expression syntax.
  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 Employee(models.Model):
  9. firstname = models.CharField(max_length=50)
  10. lastname = models.CharField(max_length=50)
  11. salary = models.IntegerField(blank=True, null=True)
  12. def __str__(self):
  13. return '%s %s' % (self.firstname, self.lastname)
  14. @python_2_unicode_compatible
  15. class Company(models.Model):
  16. name = models.CharField(max_length=100)
  17. num_employees = models.PositiveIntegerField()
  18. num_chairs = models.PositiveIntegerField()
  19. ceo = models.ForeignKey(
  20. Employee,
  21. models.CASCADE,
  22. related_name='company_ceo_set')
  23. point_of_contact = models.ForeignKey(
  24. Employee,
  25. models.SET_NULL,
  26. related_name='company_point_of_contact_set',
  27. null=True)
  28. def __str__(self):
  29. return self.name
  30. @python_2_unicode_compatible
  31. class Number(models.Model):
  32. integer = models.BigIntegerField(db_column='the_integer')
  33. float = models.FloatField(null=True, db_column='the_float')
  34. def __str__(self):
  35. return '%i, %.3f' % (self.integer, self.float)
  36. class Experiment(models.Model):
  37. name = models.CharField(max_length=24)
  38. assigned = models.DateField()
  39. completed = models.DateField()
  40. estimated_time = models.DurationField()
  41. start = models.DateTimeField()
  42. end = models.DateTimeField()
  43. class Meta:
  44. ordering = ('name',)
  45. def duration(self):
  46. return self.end - self.start
  47. @python_2_unicode_compatible
  48. class Time(models.Model):
  49. time = models.TimeField(null=True)
  50. def __str__(self):
  51. return "%s" % self.time
  52. @python_2_unicode_compatible
  53. class UUID(models.Model):
  54. uuid = models.UUIDField(null=True)
  55. def __str__(self):
  56. return "%s" % self.uuid