Hi i added custom validation.It is throwing a TypeError saying issubclass() arg 1 must be a class. and my code in admin.py is
Hi,我添加了自定义验证。它抛出一个TypeError,说issubclass() arg 1必须是一个类。还有我的管理员代码。py是
class AppraisalScheduleAdmin(admin.ModelAdmin):
exclude = ['intUpdatedBy']
form = 'tbmstappraisalschedForm'
def save_model(self, request, obj, form, change):
obj.intUpdatedBy = request.user.id
obj.save()
class tbmstappraisalschedForm(forms.ModelForm):
def clean(self):
"""
Override the default clean method to check whether this course has been already inputted.
"""
cleaned_data = super(tbmstappraisalschedForm, self).clean()
depart_id = cleaned_data.get('intDeptID')
fromdate = cleaned_data.get('sdtFromDate')
todate = cleaned_data.get('todate')
matching_records = tbmstappraisalsched.objects.filter(intDeptID=depart_id)
if self.instance:
matching_records.exclude(pk=self.instance.pk)
if matching_records.exists():
msg = "The slot for selected department and selected dates exists" % name
raise ValidationError(msg)
else:
return self.cleaned_data
class Meta:
model = tbmstappraisalsched
the traceback is
回溯是
Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 103. resolver_match = resolver.resolve(request.path_info) File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve 319. for pattern in self.url_patterns: File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in url_patterns 347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in urlconf_module 342. self._urlconf_module = import_module(self.urlconf_name) File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module 35. import(name) File "C:\pythonprgs\opas\opas\urls.py" in 5. admin.autodiscover() File "C:\Python27\lib\site-packages\django\contrib\admin__init__.py" in autodiscover 29. import_module('%s.admin' % app) File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module 35. import(name) File "C:\pythonprgs\opas\schdeules\admin.py" in 60. admin.site.register(tbmstappraisalsched,AppraisalScheduleAdmin) File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in register 98. validate(admin_class, model) File "C:\Python27\lib\site-packages\django\contrib\admin\validation.py" in validate 25. validate_base(cls, model) File "C:\Python27\lib\site-packages\django\contrib\admin\validation.py" in validate_base 317. if hasattr(cls, 'form') and not issubclass(cls.form, BaseModelForm):
回溯:文件C:\ Python27 \ lib \网站\ django \ \ \处理器核心基地。在103年get_response py”。resolver_match = resolver.resolve(request.path_info)文件”C:\Python27\lib\ lib\site-packages\django\core\urlresolvers)py 319年解决”。在自动模式。url_patterns:文件C:\ Python27 \ lib \网站\ django \ \ urlresolvers核心。在347年url_patterns py”。模式= getattr(自我。urlconf_module,“urlpatterns”,self.urlconf_module”文件“C:\Python27\lib\ lib\site-packages\django\core\urlresolvers”。在342年urlconf_module py”。自我。_urlconf_module = import_module(self.urlconf_name)文件”C:\Python27\lib\ lib\ lib -packages\django\utils\importlib。py”import_module 35。(名字)文件导入“C:\ pythonprgs \赞助方\赞助方\ url。py”5。admin.autodiscover()文件“C:\ Python27 django \ lib \网站\ \ contrib \ admin__init__。py”autodiscover 29。import_module(' % s。管理' %应用程序)文件"C:\Python27\lib\位置包\django\utils\importlib。py”import_module 35。导入文件(名称)“C:\ pythonprgs \赞助方\ schdeules \ admin。py”在60。admin.site.register”(tbmstappraisalsched AppraisalScheduleAdmin)文件C:\ Python27 django \ lib \网站\ \ contrib \ admin \网站。py”98年注册。验证文件(admin_class、模型)“C:\ Python27 \ lib \网站\ django \ contrib \ admin \验证。py”验证25。validate_base(cls模型)”文件C:\ Python27 \ lib \网站\ django \ contrib \ admin \验证。在317年validate_base py”。如果hasattr(cls, 'form')而不是issubclass(cls)。形式,BaseModelForm):
Exception Type: TypeError at /admin/schdeules/tbmstappraisalsched/add/ Exception Value: issubclass() arg 1 must be a class
异常类型:/admin/schdeules/ tbmstap草原/add/ Exception值的类型错误:issubclass() arg 1必须是一个类
1 个解决方案
#1
1
Please see below code of admin.py
请参见下面的admin.py代码
from .forms import tbmstappraisalschedForm
class AppraisalScheduleAdmin(admin.ModelAdmin):
exclude = ['intUpdatedBy']
# form = 'tbmstappraisalschedForm' you can not pass a string here .
form = tbmstappraisalschedForm #do like this
def save_model(self, request, obj, form, change):
obj.intUpdatedBy = request.user.id
obj.save()
#1
1
Please see below code of admin.py
请参见下面的admin.py代码
from .forms import tbmstappraisalschedForm
class AppraisalScheduleAdmin(admin.ModelAdmin):
exclude = ['intUpdatedBy']
# form = 'tbmstappraisalschedForm' you can not pass a string here .
form = tbmstappraisalschedForm #do like this
def save_model(self, request, obj, form, change):
obj.intUpdatedBy = request.user.id
obj.save()