Git
- 1 ответ
- 0 вопросов
2
Вклад в тег
git remote add origin ssh://server.com/home/username/git/exampleproject
git clone ssh://server.com/home/username/git/exampleproject
class Blablabla(models.Model):
start_t = models.TimeField(u"From", blank=True, null=True)
end_t = models.TimeField(u"To", blank=True, null=True)
def period_duration(self):
"""
Returns the length of the period between
start_t and end_t, in hours.
This is precise as long as both values
have 0 as minute/second.
"""
return self.end_t.hour - self.start_t.hour
class BlablablaTestCase(TestCase):
def setUp(self):
start_t = datetime.time(14)
end_t = datetime.time(18)
self.blablabla_obj = Blablabla.objects.create(
start_t=start_t,
end_t=end_t
)
def test_period_calculation(self):
"""
Tests that the period_duration method of the Blablabla
model correctly compares start_t and end_t.
"""
self.assertEqual(self.blablabla_obj.period_duration(), 4)
def tearDown(self):
self.blablabla_obj.delete()
def period_duration(self):
"""
Returns the length of the period between
start_t and end_t, in the following format:
HH:MM:SS
"""
total_seconds = (
(
self.end_t.hour*3600
+
self.end_t.minute*60
+
self.end_t.second
) - (
self.start_t.hour*3600
+
self.start_t.minute*60
+
self.start_t.second
)
)
hour, total_seconds = divmod(total_seconds, 3600)
minute, total_seconds = divmod(total_seconds, 60)
second = total_seconds
return "%02d:%02d:%02d" % (hour, minute, second)
class OrdersAdmin(admin.ModelAdmin):
fields = [
'customer',
'customer_address',
'date',
'amount_bottle',
'price',
'statusOrder'
]
readonly_fields = ['customer_address',]
list_filter = ['date']
date_hierarchy = 'date'
def customer_address(self, obj):
return obj.customer.address
customer_address.short_description = "Customer’s address"