當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。