Include alias and materialized fields in queryset results

This commit is contained in:
Itai Shirav 2018-08-19 16:18:15 +03:00
parent 238fd11d6b
commit 32c77ab190
3 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,10 @@
Change Log
==========
Unreleased
----------
- Include alias and materialized fields in queryset results
v1.0.1
------
- NullableField: take extra_null_values into account in `validate` and `to_python`

View File

@ -237,7 +237,7 @@ class QuerySet(object):
self._database = database
self._order_by = []
self._q = []
self._fields = []
self._fields = model_cls.fields().keys()
self._limits = None
self._distinct = False

View File

@ -220,6 +220,18 @@ class QuerySetTestCase(TestCaseWithData):
self._test_qs(qs, 100)
self._test_qs(qs.only('first_name'), 94)
def test_materialized_field(self):
self._insert_sample_model()
qs = SampleModel.objects_in(self.database)
for obj in qs:
self.assertTrue(obj.materialized_date != DateField.min_value)
def test_alias_field(self):
self._insert_sample_model()
qs = SampleModel.objects_in(self.database)
for obj in qs:
self.assertTrue(obj.num_squared == obj.num ** 2)
class AggregateTestCase(TestCaseWithData):
@ -358,6 +370,7 @@ class SampleModel(Model):
materialized_date = DateField(materialized='toDate(timestamp)')
num = Int32Field()
color = Enum8Field(Color)
num_squared = Int32Field(alias='num*num')
engine = MergeTree('materialized_date', ('materialized_date',))