當前位置: 首頁>>代碼示例>>Python>>正文


Python ContentType.name方法代碼示例

本文整理匯總了Python中django.contrib.contenttypes.models.ContentType.name方法的典型用法代碼示例。如果您正苦於以下問題:Python ContentType.name方法的具體用法?Python ContentType.name怎麽用?Python ContentType.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.contenttypes.models.ContentType的用法示例。


在下文中一共展示了ContentType.name方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: text_description_to_model

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import name [as 別名]
def text_description_to_model(module, text, app_label, admin_register=True):
    dct = yaml.load(text)
    for model_name in dct.keys():
        fields = dct[model_name]['fields']
        attrs = {}

        for field in fields:
            attrs[field['id']] = _field_by_type(field['type'], field['title'])

        attrs['__module__'] = module.__name__

        model_name = str(model_name).capitalize()
        NewModel = type(model_name, (Model,), attrs)

        setattr(module, model_name, NewModel)

        new_ct = ContentType()
        new_ct.app_label = app_label
        new_ct.name = model_name
        new_ct.model = model_name.lower()
        new_ct.save()

        if admin_register:

            class Admin(admin.ModelAdmin):
                pass

            admin.site.register(NewModel, Admin)

    if admin_register:
        reload(import_module(settings.ROOT_URLCONF))
        clear_url_caches()
開發者ID:stushurik,項目名稱:django_dynamic_models,代碼行數:34,代碼來源:utils.py

示例2: install

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import name [as 別名]
def install(sender, created_models, **kwargs):
    for model in get_models():  # TODO change to django.apps
        if getattr(model, 'BMFMeta', False):

            kwargs = {
                'app_label': model._meta.app_label,
                'model': model._meta.model_name,
            }

            # LOOK: maybe we could move this to a signal
            try:
                ct = ContentType.objects.get(**kwargs)
            except ContentType.DoesNotExist:
                ct = ContentType(**kwargs)
                ct.name = model._meta.verbose_name_raw
                ct.save()

            if model._bmfmeta.number_cycle:
                count = NumberCycle.objects.filter(ct=ct).count()
                if not count:
                    obj = NumberCycle(ct=ct, name_template=model._bmfmeta.number_cycle)
                    obj.save()
    return None
開發者ID:dmatthes,項目名稱:django-bmf,代碼行數:25,代碼來源:management.py

示例3: on_add_module

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import name [as 別名]
def on_add_module(request,module_type,parent_id):
	context = {}
	try:
		parent = Module.objects.get(id=parent_id)
		context.update({'parent_name':parent.name})
		context.update({'app_name':parent.app.name})
		# title
		title = ""
		if module_type=="G":
			title = _(u"THÊM NHÓM MODULE")
		elif module_type=="M":
			title = _(u"THÊM MODULE")
		elif module_type=="P":
			title = _(u"THÊM QUYỀN")
		context.update({'title':title})
		if request.POST:
			#auto commit
			transaction.set_autocommit(False)
			#parameter
			code = request.POST["txtCode"]
			name = request.POST["txtName"]
			action = request.POST["txtAction"]
			url = request.POST["txtUrl"]
			icon = request.POST["txtIcon"]
			ord_num = request.POST["txtOrd"]
			#new Module
			module = Module()
			module.code = code
			module.name = name
			module.action = action
			module.url = url
			module.type = module_type
			module.icon_class = icon
			module.ord = ord_num
			if request.POST.get('ckStatus'):
				module.status = "1"
			else:
				module.status = "0"
			module.parent = parent
			module.app = parent.app
			module.user_name = request.user.username
			if module_type=="M":
				#Insert content type
				content_type = ContentType()
				content_type.app_label = parent.app.code
				content_type.model = code
				content_type.name = name
				content_type.save()
				module.content_type = content_type
			elif module_type=="P":
				#Insert permission
				permission = Permission()
				permission.content_type = parent.content_type
				permission.name = name
				permission.codename = code
				permission.save()
				module.permission = permission
			#save module
			module.save()
			#commit
			transaction.commit()
			return HttpResponseRedirect(str("%s?app_id="+str(parent.app.id)) % resolve_url("module"))
	except Exception as ex:
		transaction.rollback()
		context.update({'has_error':str(ex)})
	finally:
		context.update(csrf(request))
	return render_to_response("admin/module/add-module.html", context, RequestContext(request))
開發者ID:ngotuan12,項目名稱:AssetManagement,代碼行數:70,代碼來源:UserPermission.py


注:本文中的django.contrib.contenttypes.models.ContentType.name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。