tags:

views:

504

answers:

2

I'm having a problem while trying to call a custom Model method from my Form clean method.

Here is [part of] my model:
http://dpaste.com/hold/12695/

Here is my Form:
http://dpaste.com/hold/12699/

I'm specifically having a problem with line 11 in my Form:
nzb_data = File.get_nzb_data(nzb_absolute)

This raises the following error:

TypeError at /admin/main/file/add/

unbound method get_nzb_data() must be called with File instance as first argument (got str instance instead)

By this error I can assume I have to pass the method something (a File instance), however I don't really know what that means and how I can do it.

Can you let me know what I'm doing wrong here, and what can be done to resolve the issue?


Solved by making the get_nzb_data method a class method using the @classmethod decorator.

+3  A: 

You can't call

nzb_data = File.get_nzb_data(nzb_absolute)

because your using the class, not an object.

You have two choices.

  1. Make get_nzb_data a @classmethod. See http://docs.python.org/library/functions.html#classmethod

  2. Create an instance of File and use that. temp_f= File(...). Then temp_f.get_dnb_data.

S.Lott
Absolutely right
aatifh
Thank you for clearing that up. It's working perfectly now.
Ty
+1  A: 

I may be missing something here, but I think that your method ´get_nzb_data´ should have a @classmethod decorator. Otherwise, it expects the ´self´ argument of the type File, and this gives that error.

Tiago