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


Python ContentType.model方法代碼示例

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


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

示例1: text_description_to_model

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import model [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: test_ignore_edit

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import model [as 別名]
    def test_ignore_edit(self):
        """
        Tests if changing instance of a model from ignore list
        would not create db entry"""

        c = ContentType(app_label='hello', model='abc')
        c.save()
        old_count = ModelChange.objects.count()
        c.model = 'cba'
        c.save()
        new_count = ModelChange.objects.count()
        self.assertEqual(old_count, new_count)
開發者ID:Yevs,項目名稱:FortyTwoTestTask,代碼行數:14,代碼來源:test_signal.py

示例3: setUp

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import model [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()
開發者ID:caep-unb,項目名稱:gestorpsi,代碼行數:45,代碼來源:tests_models.py

示例4: on_add_module

# 需要導入模塊: from django.contrib.contenttypes.models import ContentType [as 別名]
# 或者: from django.contrib.contenttypes.models.ContentType import model [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.model方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。