Tuesday, September 20, 2011

Re: Custom model field/form: __init__() got multiple values for keyword argument 'baz'

On Tue, Sep 20, 2011 at 3:36 PM, Michal Petrucha <michal.petrucha@ksp.sk> wrote:
> Well, the problem is that your defined fields.TestField.__init__ takes
> baz as either a keyword argument, or as the first positional arg. As
> with related fields, to pass the verbose name in this case you have to
> specify it as a keyword argument as well or specify your custom
> argument first and shift all other positional arguments. So, to fix
> your issue, choose either of the two following::

Ahhh, thank you for the clarification and for providing me with a
solution!!! I really appreciate it. :)

For some reason, I never thought to re-arrange the order of the
args/kwargs in the model TestField().

Optimally, I think I would prefer to keep the verbose name in the
first position (as an arg, not kwarg) in order to keep things
consistent.

If you look at fields.py:

<https://gist.github.com/1229708#file_fields.py>

Line #s 13 and 16, I do this:

def __init__(self, *args, **kwargs):
self._baz = kwargs.get('baz', None)

But when I do that, I get this error:

File "/.../test/fields.py", line 19, in __init__
TypeError: __init__() got an unexpected keyword argument 'baz'

Is there a way to pass around keyword arguments (from the model
TestField()) without having to be explicit?

Sorry if noob questions. I still consider myself a Python/Django noobie :)

A billion thanks for all of your help! I really appreciate it.

Have a nice day!

Cheers
Micky

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate