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::
foo = TestField(baz='bar', verbose_name=u'Foo field',
max_length=100, help_text='Foo baz bar?')
foo = TestField('bar', u'Foo field', max_length=100,
help_text='Foo baz bar?')
Michal
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
In this case, the problem is a little bit different.
models.CharField.__init__ knows nothing about any 'baz' keyword
argument. With your current code, however, you keep the 'baz' item in
the kwargs dictionary and also pass this argument to
CharField.__init__. That's the cause of this error.
The remedy is simple, instead of kwargs.get use kwargs.pop.
Michal
Ahhh, I see! Thanks so much for the explanation and clarification.
Much appreciated.
Have an excellent day!
Cheers,
Micky