本文整理汇总了Python中avocado.models.DataConcept.order方法的典型用法代码示例。如果您正苦于以下问题:Python DataConcept.order方法的具体用法?Python DataConcept.order怎么用?Python DataConcept.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类avocado.models.DataConcept
的用法示例。
在下文中一共展示了DataConcept.order方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _migrate_concept
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import order [as 别名]
def _migrate_concept(self, model, migrate_func, **options):
no_input = options.get('no_input')
total_migrated = 0
for lc in model.objects.iterator():
field_nks = list(lc.fields.values('app_name', 'model_name',
'field_name').distinct())
field_cond = Q()
for f in field_nks:
field_cond = field_cond | Q(**f)
fields = DataField.objects.filter(field_cond).distinct()
# Mismatch of fields from new to old
if len(fields) != len(field_nks):
print('One or more fields mismatched for "{0}". '
'Skipping...'.format(lc))
continue
matches = DataConcept.objects.filter(name=lc.name)
# Filter concepts by existence of fields
for f in fields:
matches = matches.filter(fields__app_name=f.app_name,
fields__model_name=f.model_name,
fields__field_name=f.field_name)
num = len(matches)
if num > 1:
print('{0} have the same name and fields. '
'Skipping...'.format(num))
continue
if num == 1:
c = matches[0]
existing = True
if not no_input:
override = True
while True:
response = raw_input(u'Match found for "{0}". '
'Override? [n/Y] '.format(c))
if not response:
break
if response.lower() == 'n':
override = False
break
if not override:
continue
else:
c = DataConcept(queryable=False, viewable=False)
existing = False
c.name = lc.name
c.order = lc.order
c.published = lc.is_public
# This looks odd, but this handles choosing the longer of the two
# descriptions for criterion and column if both exist.
if not c.description or lc.description and \
len(lc.description) > len(c.description):
c.description = lc.description
if lc.category:
try:
kwargs = {
'name__iexact': lc.category.name,
}
# Filter by parent if one exists since categories with the
# same name can exists as sub-categories.
if lc.category.parent_id:
kwargs['parent__name'] = lc.category.parent.name
c.category = DataCategory.objects.get(**kwargs)
except DataCategory.DoesNotExist:
pass
# Apply migration specific function to concept from legacy concept
migrate_func(c, lc)
# Save for foreign key references to concept fields
c.save()
cfs = []
if not existing:
lcfs = list(lc.conceptfields.select_related('field'))
# Dict of legacy concept fields to the new field it
# corresponds to
lcf_map = {}
for lcf in lcfs:
for f in fields:
# Match and break
if lcf.field.natural_key() == f.natural_key():
lcf_map[lcf.pk] = f
break
#.........这里部分代码省略.........