【发布时间】:2011-03-22 02:33:20
【问题描述】:
我不知道我是否清楚标题问题,我想做的是下一个案例:
>>> from django.contrib.contenttypes.models import ContentType
>>> ct = ContentType.objects.get(model='user')
>>> ct.model_class()
<class 'django.contrib.auth.models.User'>
>>> ct_class = ct.model_class()
>>> ct_class.username = 'hellow'
>>> ct_class.save()
TypeError: unbound method save() must be called with User instance as first argument (got nothing instead)
我只想实例化通过内容类型获得的任何模型。
之后我需要做类似 form = create_form_from_model(ct_class)
并准备好使用此模型表单。
提前谢谢你!
【问题讨论】:
标签: python django django-contenttypes