[Answer]-Django 1.2 modelAdmin inherited class, error "get_form() takes exactly 3 arguments (2 given)"

1👍

There are a couple of errors here.

Firstly, the original signature of the get_form method is def get_form(self, request, obj=None, **kwargs) – that is, the obj argument is optional (which makes sense, as when you’re creating a new item, there is no existing object). However, you’ve overridden it with this: def get_form(self, request, obj, **kwargs) – ie now the obj argument is required.

Unless you have complete control over how your method is going to be called – which you don’t in this case, because it’s done by the admin – you should ensure that your method can accept the same arguments as the original, at the very least.

Your second error is in the next line:

form = super(FilerVariant,self).get_form(self,request, obj,**kwargs)

Here you’ve duplicated the self argument – you mustn’t pass it explicitly in the method call, as it’s already passed as the first argument.

Finally, you should definitely think about upgrading – Django 1.2 was released two years ago, there’s been a lot of changes since then.

Leave a comment