本文整理汇总了Python中django.contrib.contenttypes.models.ContentType.app_label方法的典型用法代码示例。如果您正苦于以下问题:Python ContentType.app_label方法的具体用法?Python ContentType.app_label怎么用?Python ContentType.app_label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.contenttypes.models.ContentType
的用法示例。
在下文中一共展示了ContentType.app_label方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: text_description_to_model
# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import app_label [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()
示例2: setUp
# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import app_label [as 别名]
def setUp(self):
person = Person()
User.objects.create(username="user1", password="password")
person.user = User.objects.get(username="user1")
person.birthDate = "1990-05-14"
person.birthForeignCity = "Melbourne"
person.birthForeignState = "Victoria"
person.birthForeignCountry = '1'
person.save()
contentType = ContentType()
contentType.app_label = "auth"
contentType.model = "any"
contentType.save()
emailType = EmailType()
emailType.description = "Email Type"
emailType.save()
email = Email()
email.email = "[email protected]"
email.email_type = EmailType.objects.all()[0]
email.content_object = person
email.save()
site = Site()
site.description = "this is a website"
site.site = "www.google.com.br"
site.content_object = person
site.save()
person.save()
self.p = Person.objects.get(user_id=person.user.id)
def tearDown(self):
for person in Person.objects.all():
person.delete()
for user in User.objects.all():
user.delete()
示例3: on_add_module
# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import app_label [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))