2009-01-29 18:46:36 +08:00
|
|
|
"""
|
|
|
|
Tests for F() query expression syntax.
|
|
|
|
"""
|
2017-05-30 18:40:41 +08:00
|
|
|
import uuid
|
2014-04-21 18:15:04 +08:00
|
|
|
|
2009-01-29 18:46:36 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2020-04-05 02:55:20 +08:00
|
|
|
class Manager(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
|
2009-01-29 18:46:36 +08:00
|
|
|
class Employee(models.Model):
|
|
|
|
firstname = models.CharField(max_length=50)
|
|
|
|
lastname = models.CharField(max_length=50)
|
2015-03-04 20:56:20 +08:00
|
|
|
salary = models.IntegerField(blank=True, null=True)
|
2020-04-05 02:55:20 +08:00
|
|
|
manager = models.ForeignKey(Manager, models.CASCADE, null=True)
|
2009-01-29 18:46:36 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '%s %s' % (self.firstname, self.lastname)
|
2009-01-29 18:46:36 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2019-01-16 13:39:49 +08:00
|
|
|
class RemoteEmployee(Employee):
|
|
|
|
adjusted_salary = models.IntegerField()
|
|
|
|
|
|
|
|
|
2009-01-29 18:46:36 +08:00
|
|
|
class Company(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
num_employees = models.PositiveIntegerField()
|
|
|
|
num_chairs = models.PositiveIntegerField()
|
|
|
|
ceo = models.ForeignKey(
|
|
|
|
Employee,
|
2015-07-22 22:43:21 +08:00
|
|
|
models.CASCADE,
|
2018-03-16 17:54:34 +08:00
|
|
|
related_name='company_ceo_set',
|
|
|
|
)
|
2009-01-29 18:46:36 +08:00
|
|
|
point_of_contact = models.ForeignKey(
|
|
|
|
Employee,
|
2015-07-22 22:43:21 +08:00
|
|
|
models.SET_NULL,
|
2009-01-29 18:46:36 +08:00
|
|
|
related_name='company_point_of_contact_set',
|
2018-03-16 17:54:34 +08:00
|
|
|
null=True,
|
|
|
|
)
|
2017-02-27 17:01:52 +08:00
|
|
|
based_in_eu = models.BooleanField(default=False)
|
2009-01-29 18:46:36 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-01-29 18:46:36 +08:00
|
|
|
return self.name
|
2014-04-21 18:15:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Number(models.Model):
|
|
|
|
integer = models.BigIntegerField(db_column='the_integer')
|
|
|
|
float = models.FloatField(null=True, db_column='the_float')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return '%i, %.3f' % (self.integer, self.float)
|
|
|
|
|
|
|
|
|
|
|
|
class Experiment(models.Model):
|
|
|
|
name = models.CharField(max_length=24)
|
|
|
|
assigned = models.DateField()
|
|
|
|
completed = models.DateField()
|
2014-07-24 20:57:24 +08:00
|
|
|
estimated_time = models.DurationField()
|
2014-04-21 18:15:04 +08:00
|
|
|
start = models.DateTimeField()
|
|
|
|
end = models.DateTimeField()
|
|
|
|
|
|
|
|
class Meta:
|
2017-10-26 03:52:38 +08:00
|
|
|
db_table = 'expressions_ExPeRiMeNt'
|
2014-04-21 18:15:04 +08:00
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def duration(self):
|
|
|
|
return self.end - self.start
|
2015-01-02 09:39:31 +08:00
|
|
|
|
|
|
|
|
2016-06-03 02:05:25 +08:00
|
|
|
class Result(models.Model):
|
|
|
|
experiment = models.ForeignKey(Experiment, models.CASCADE)
|
|
|
|
result_time = models.DateTimeField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Result at %s" % self.result_time
|
|
|
|
|
|
|
|
|
2015-01-02 09:39:31 +08:00
|
|
|
class Time(models.Model):
|
|
|
|
time = models.TimeField(null=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s" % self.time
|
|
|
|
|
|
|
|
|
2016-06-03 02:05:25 +08:00
|
|
|
class SimulationRun(models.Model):
|
2016-03-18 22:24:29 +08:00
|
|
|
start = models.ForeignKey(Time, models.CASCADE, null=True, related_name='+')
|
|
|
|
end = models.ForeignKey(Time, models.CASCADE, null=True, related_name='+')
|
2016-06-03 02:05:25 +08:00
|
|
|
midpoint = models.TimeField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s (%s to %s)" % (self.midpoint, self.start, self.end)
|
|
|
|
|
|
|
|
|
2017-05-30 18:40:41 +08:00
|
|
|
class UUIDPK(models.Model):
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
|
|
|
|
|
|
|
|
2015-01-02 09:39:31 +08:00
|
|
|
class UUID(models.Model):
|
|
|
|
uuid = models.UUIDField(null=True)
|
2017-05-30 18:40:41 +08:00
|
|
|
uuid_fk = models.ForeignKey(UUIDPK, models.CASCADE, null=True)
|