should i have to open a ticket?

On 14 Nov, 23:19, Ric <riccardodivirgi...@gmail.com> wrote:
> form_class is not in kwargs if the method is declared like this
>
> def formfield(self, form_class=forms.CharField, **kwargs):
>
> a possible solution is to use a code like this
>
> def formfield(self, **kwargs):
>     form_class = kwargs.pop("form_class", self.choices and
> forms.TypedChoiceField or forms.CharField)
>
> in that way is no form_class is passed, a default form_class is
> defined (TypedChoiceField or CharField)
>
> On 14 Nov, 21:22, Ric <riccardodivirgi...@gmail.com> wrote:
>
>
>
>
>
>
>
> > yes but definitely not the current code, because i cannot subclass
> > with super
>
> > On 14 Nov, 15:46, ptone <pres...@ptone.com> wrote:
>
> > > On Nov 13, 11:55 pm, Ric <riccardodivirgi...@gmail.com> wrote:
>
> > > > the field class define this code
>
> > > >     def formfield(self, form_class=forms.CharField, **kwargs):
> > > >         """
> > > >         Returns a django.forms.Field instance for this database Field.
> > > >         """
> > > >         defaults = {'required': not self.blank,
> > > >                     'label': capfirst(self.verbose_name),
> > > >                     'help_text': self.help_text}
> > > >         if self.has_default():
> > > >             if callable(self.default):
> > > >                 defaults['initial'] = self.default
> > > >                 defaults['show_hidden_initial'] = True
> > > >             else:
> > > >                 defaults['initial'] = self.get_default()
> > > >         if self.choices:
> > > >             # Fields with choices get special treatment.
> > > >             include_blank = (self.blank or
> > > >                              not (self.has_default() or 'initial' in
> > > > kwargs))
> > > >             defaults['choices'] =
> > > > self.get_choices(include_blank=include_blank)
> > > >             defaults['coerce'] = self.to_python
> > > >             if self.null:
> > > >                 defaults['empty_value'] = None
> > > >             form_class = forms.TypedChoiceField
> > > >             # Many of the subclass-specific formfield arguments
> > > > (min_value,
> > > >             # max_value) don't apply for choice fields, so be sure to
> > > > only pass
> > > >             # the values that TypedChoiceField will understand.
> > > >             for k in kwargs.keys():
> > > >                 if k not in ('coerce', 'empty_value', 'choices',
> > > > 'required',
> > > >                              'widget', 'label', 'initial',
> > > > 'help_text',
> > > >                              'error_messages', 'show_hidden_initial'):
> > > >                     del kwargs[k]
> > > >         defaults.update(kwargs)
> > > >         return form_class(**defaults)
>
> > > > this code says
> > > > if self.choices:
> > > >     form_class = forms.TypedChoiceField
>
> > > > this means that if you have a field that got choices, even if you pass
> > > > during the super an argument different than forms.TypedChoiceField,
> > > > you'll always get forms.TypedChoiceField
>
> > > > must be defaults["form_class"] = forms.TypedChoiceField
>
> > > do you mean something like:
>
> > > if self.choices:
> > >     if 'form_class' in defaults:
> > >         form_class = defaults['form_class']
> > >     else:
> > >         form_class = forms.TypedChoiceField
>
> > > -Preston
> > > form_class =

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

Reply via email to