本文整理汇总了Python中models.Report.model方法的典型用法代码示例。如果您正苦于以下问题:Python Report.model方法的具体用法?Python Report.model怎么用?Python Report.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Report
的用法示例。
在下文中一共展示了Report.model方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: report_add
# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import model [as 别名]
def report_add(request, response_format='html'):
"Create new report based on user choice"
if 'report' in request.POST:
report_id = request.POST['report']
return HttpResponseRedirect(reverse('reports_report_edit', args=[report_id]))
# FIRST TIME AN OBJECT IS CHOSEN
if 'choice' in request.POST:
form = None
object = request.POST['choice']
object = str(
object.replace("{'object_type': u'", '').replace("'}", ''))
full_object = object
object = object.split('.', 3)
module_name = object[0] + '.' + object[1] + '.' + object[2]
import_name = object[3]
module = __import__(
module_name, globals(), locals(), [import_name], -1)
classobj = getattr(module, import_name)
obj = classobj()
names = obj.get_field_names()
fields = []
for name in names:
fields.append(Field(name=name, display=True))
model = Model(full_object, fields)
report = Report()
report.name = "Untitled {0!s} Report".format((obj._meta.object_name))
report.model = dumps(model)
report.creator = request.user.profile
report.save()
return HttpResponseRedirect(reverse('reports_report_edit', args=[report.id]))
# Initial Object Type Choice
user_modules = [mod.name for mod in request.user.profile.get_perspective().get_modules()]
modules = [mod.name for mod in Module.objects.all()]
query = Q(object_type__contains="core")
for module in modules:
if module not in user_modules:
query = query | Q(object_type__contains=module)
object_types = list(Object.objects.all().exclude(query).values(
'object_type').distinct().order_by('object_type'))
object_names = []
for object_type in object_types:
module_name = _get_module_name(object_type['object_type'])
human_type = Object.objects.filter(
object_type=object_type['object_type'])[0].get_human_type()
object_names.append("{0!s}: {1!s}".format(module_name, human_type))
form = ObjChoiceForm(request.user, object_types=object_types, object_names=object_names)
return render_to_response('reports/report_add', {'form': form}, context_instance=RequestContext(request),
response_format=response_format)