本文整理汇总了Python中avocado.models.DataView.apply方法的典型用法代码示例。如果您正苦于以下问题:Python DataView.apply方法的具体用法?Python DataView.apply怎么用?Python DataView.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类avocado.models.DataView
的用法示例。
在下文中一共展示了DataView.apply方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sort_related
# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
def test_sort_related(self):
"Sorts on a reverse foreign key property."
view = DataView(
json=[
{"concept": self.first_name.pk},
{"concept": self.last_name.pk},
{"concept": self.project_name.pk, "sort": "asc", "visible": False},
]
)
queryset = view.apply()
exporter = export.BaseExporter(view)
exporter.params.insert(0, (RawFormatter(keys=["pk"]), 1))
exporter.row_length += 1
self.assertEqual(
list(exporter.write(queryset.raw())),
[
(3, u"Erick", u"Smith"),
(4, u"Aaron", u"Harris"),
(5, u"Zac", u"Cook"),
(6, u"Mel", u"Brooks"),
(1, u"Eric", u"Smith"),
(2, u"Erin", u"Jones"),
],
)
示例2: setUp
# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
def setUp(self):
management.call_command("avocado", "init", "tests", quiet=True)
salary_concept = DataField.objects.get(field_name="salary").concepts.all()[0]
view = DataView(json={"ordering": [[salary_concept.pk, "desc"]]})
self.query = view.apply(tree=models.Employee).raw()
# Ick..
self.exporter = export.BaseExporter(view)
self.exporter.params.insert(0, (RawFormatter(keys=["pk"]), 1))
self.exporter.row_length += 1
示例3: test_dataview_order_by
# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
def test_dataview_order_by(self):
f = DataField(app_name='lexicon', model_name='month', field_name='id')
f.save()
c = DataConcept()
c.save()
cf = DataConceptField(field=f, concept=c)
cf.save()
v = DataView({'ordering': [c.pk]})
qs = Month.objects.filter(label__startswith='J').values('id')
self.assertEqual(str(v.apply(qs).query), 'SELECT "lexicon_month"."id" FROM "lexicon_month" WHERE "lexicon_month"."label" LIKE J% ESCAPE \'\\\' ORDER BY "lexicon_month"."order" ASC')
示例4: test_view
# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
def test_view(self):
salary_field = DataField.objects.get_by_natural_key('exporting', 'title', 'salary')
salary_concept = DataConcept()
salary_concept.save()
DataConceptField(concept=salary_concept, field=salary_field, order=1).save()
view = DataView(json={'ordering': [[salary_concept.pk, 'desc']]})
query = view.apply(tree=models.Employee).raw()
# Ick..
exporter = export.CSVExporter(view)
exporter.params.insert(0, (RawFormatter(keys=['pk']), 1))
exporter.row_length += 1
buff = exporter.write(query)
buff.seek(0)
lines = buff.read().splitlines()
# Skip the header
self.assertEqual([int(x) for x in lines[1:]], [2, 4, 6, 1, 3, 5])