当前位置: 首页>>代码示例>>Python>>正文


Python ContentType.model_class方法代码示例

本文整理汇总了Python中django.contrib.contenttypes.models.ContentType.model_class方法的典型用法代码示例。如果您正苦于以下问题:Python ContentType.model_class方法的具体用法?Python ContentType.model_class怎么用?Python ContentType.model_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.contenttypes.models.ContentType的用法示例。


在下文中一共展示了ContentType.model_class方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: json_list

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
def json_list(request,app,model,lookup,value):
	content = ContentType(app_label=app,model=model)
	contentclass = content.model_class()
	lookup_dict = { lookup:value }
	queryset = contentclass.objects.filter(**lookup_dict)
	return HttpResponse(serializers.serialize('json', queryset),
                        mimetype='application/json')
开发者ID:egasimus,项目名称:django-multistep-select,代码行数:9,代码来源:views.py

示例2: get_validation_errors

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
 def get_validation_errors(self, token):
     model_class = ContentType.model_class(self.lookup_type)
     vals = model_class.objects.values_list(self.field_name, flat=True)
     print "validating %s with %s" % (token, str(self))
     if token not in vals:
         return "%s not in list of %s %s" % (token, self.lookup_type.name, self.field_name)
     return None
开发者ID:rtighe,项目名称:rapidsms,代码行数:9,代码来源:models.py

示例3: get_typeahead

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
def get_typeahead(request):
	if request.is_ajax() and request.method == "POST":
		if ('field' in request.POST and 
			'app' in request.POST and 
			'model' in request.POST):
			ct = ContentType.objects.get_by_natural_key(request.POST['app'],
				request.POST['model'])
			instance = ContentType.model_class(ct)
			f = dict([(x,x) for x in instance._meta.get_all_field_names() ])
			try:
				o = f[request.POST['field']]
				o = instance._meta.get_field_by_name(o)[0]
			except KeyError:
				return HttpResponseForbidden('[{"error":"Forbidden"}]', 
					mimetype='application/json; charset=utf8')
			o = o.related.parent_model
			obj_list = o.objects.all()
			lst = {}
			for i,obj in enumerate(obj_list):
				l = {}
				l.update({"id":obj.id})
				l.update({"unicode":obj.__unicode__()}) 
				#not sure about __unicode__, actually
				lst.update({i:l})
			return HttpResponse(json.dumps(lst, indent = 4 * ' '), 
				mimetype='application/json; charset=utf8')
	else:
		return HttpResponseForbidden('[{"error":"Forbidden. Wrong headers."}]', 
			mimetype='application/json; charset=utf8')
开发者ID:fynjah,项目名称:django-pimp-my-filter,代码行数:31,代码来源:views.py

示例4: get_validation_errors

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
 def get_validation_errors(self, token_value):
     model_class = ContentType.model_class(self.lookup_type)
     lookup = { str(self.field_name + "__iexact") : token_value.data } 
     try: 
         val = model_class.objects.get(**lookup)
         return None
     except model_class.DoesNotExist: 
         return "%s not in list of %s %ss" % (token_value.data, self.lookup_type.name, self.field_name) 
开发者ID:ITIDO,项目名称:rapidsms,代码行数:10,代码来源:models.py

示例5: get_absolute_url

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
 def get_absolute_url(self):
     """
     link to dorsale’s generic `show_item` view
     """
     mo = ContentType.model_class(self)
     return ('dorsale.views.show_item', (), {
         'app_name'  : mo.app_label,
         'model_name': mo.model,
         'object_id' : self.id,
     })
开发者ID:fiee,项目名称:fiee-dorsale,代码行数:12,代码来源:models.py

示例6: use_filter_internal

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
def use_filter_internal(filter_id):
	if filter_id:
		try:
			flt = Filter.objects.only('content_type').get(pk = filter_id)
		except Filter.DoesNotExist:
			return None
		model = ContentType.model_class(flt.content_type)
		kwargs = {}
		for c in flt.conditions.all():
			field = None
			lookup = c.operator
			field = "%s%s" % (c.field, lookup)
			kwargs.update({field:c.value})
		return model.objects.filter(**kwargs)
	else:
		return None
开发者ID:fynjah,项目名称:django-pimp-my-filter,代码行数:18,代码来源:views.py

示例7: use_filter

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
def use_filter(request):
	if request.is_ajax():
		if 'filter_id' in request.GET:
			try:
				flt = Filter.objects.only('content_type').get(pk = request.GET['filter_id'])
			except Filter.DoesNotExist:
				return HttpResponseForbidden('[{"error":"Filter Not found."}]', 
					mimetype='application/json; charset=utf8')
			model = ContentType.model_class(flt.content_type)
			kwargs = {}
			for c in flt.conditions.all():
				field = None
				lookup = c.operator
				field = "%s%s" % (c.field, lookup)
				kwargs.update({field:c.value})
			qs = model.objects.filter(**kwargs)
			response = {}
			for i,q in enumerate(qs):
				field_list = {}
				for f in q._meta.get_all_field_names():
					obj, model, direct, m2m = q._meta.get_field_by_name(f)
					if not direct or isinstance(obj, GenericRelation):
						continue
					if m2m:
						l = {}
						val = obj.value_from_object(q)
						for m in obj.value_from_object(q):
							l.update({m.pk:m.__unicode__()})
						field_list.update({f:l})
					elif obj.rel:
						val = q.__getattribute__(obj.name)
						if val:
							l = {val.pk:val.__unicode__()}
							field_list.update({obj.name:l})
						else:
							field_list.update({f:None})
					else:
						field_list.update({f:obj.value_to_string(q)})
				response.update({i:field_list})
			r = json.dumps(response, indent = 4 * ' ')
			return HttpResponse(r, 
				mimetype='application/json; charset=utf8')
	return HttpResponseForbidden('[{"error":"Forbidden. Wrong headers."}]', 
		mimetype='application/json; charset=utf8')
开发者ID:fynjah,项目名称:django-pimp-my-filter,代码行数:46,代码来源:views.py

示例8: get_structure

# 需要导入模块: from django.contrib.contenttypes.models import ContentType [as 别名]
# 或者: from django.contrib.contenttypes.models.ContentType import model_class [as 别名]
def get_structure(request):
	if request.method == "POST" and request.is_ajax():
		if 'app' in request.POST and 'model' in request.POST:
			fields = {}
			ct = ContentType.objects.get_by_natural_key(request.POST['app'],
				request.POST['model'])
			model = ContentType.model_class(ct)
			for i,x in enumerate(model._meta.get_all_field_names()):
				obj, m, direct, m2m = model._meta.get_field_by_name(x)

				if obj.name == 'id' or not direct or isinstance(obj, GenericRelation):
					continue
				f = {}
				f.update({"type":obj.get_internal_type()})
				f.update({"name":obj.name})
				fields.update( {i: f} )

			r = {}
			r.update({'fields':fields})
			r.update({'operators':LOGICAL_OPERATORS})
			return HttpResponse(json.dumps(r, indent = 4 * ' '), 
				mimetype='application/json; charset=utf8')
	return HttpResponseForbidden('[{"error":"Forbidden"}]', 
		mimetype='application/json; charset=utf8')
开发者ID:fynjah,项目名称:django-pimp-my-filter,代码行数:26,代码来源:views.py


注:本文中的django.contrib.contenttypes.models.ContentType.model_class方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。