0
votes

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

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):

Exception Type: TypeError at /admin/schdeules/tbmstappraisalsched/add/ Exception Value: issubclass() arg 1 must be a class

1
1. Please fix your indentation, and 2. please post the actual error and the traceback.Daniel Roseman
there are no indentation errorsRamakrishna

1 Answers

1
votes

Please see below code of 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()