Re: ModelForm removing blank=True
Brilliant. Thanks James. I went down this path of thinking but tried blank=True instead of required=False which, when it failed, confused my underslept mind :) Appreciate it. Andrew. On Dec 10, 1:03 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > On Tue, Dec 9, 2008 at 7:50 PM, tenni <[EMAIL PROTECTED]> wrote: > > "optional_field" becomes a required field in the Admin. I assume > > something is overriding the model's blank=True for this field. > > Yes. *You* are overriding that. > > The moment you override a field's definition in a ModelForm is the > moment Django assumes you know best, and so Django doesn't do *any* > automatic introspection of the model for that field. It simply assumes > that the field definition you've given is correct in every respect, > and that if it's somehow not correct you will fix it. So if the field > has "blank=True" in the model, but you give Django your own custom > definition for that field in the form, then Django goes with your > custom field (which, in this case, has "required=True" since that's > the default for all form fields unless you say otherwise). > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelForm removing blank=True
On Tue, Dec 9, 2008 at 7:50 PM, tenni <[EMAIL PROTECTED]> wrote: > "optional_field" becomes a required field in the Admin. I assume > something is overriding the model's blank=True for this field. Yes. *You* are overriding that. The moment you override a field's definition in a ModelForm is the moment Django assumes you know best, and so Django doesn't do *any* automatic introspection of the model for that field. It simply assumes that the field definition you've given is correct in every respect, and that if it's somehow not correct you will fix it. So if the field has "blank=True" in the model, but you give Django your own custom definition for that field in the form, then Django goes with your custom field (which, in this case, has "required=True" since that's the default for all form fields unless you say otherwise). -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ModelForm removing blank=True
If I do this in admin.py class UnitAdminModelForm(forms.ModelForm): optional_field = forms.CharField(widget=WYMEditor()) class Meta: model = Unit "optional_field" becomes a required field in the Admin. I assume something is overriding the model's blank=True for this field. If it helps I can paste the WYMEditor() class too... All I want to do is render this particular field with a rich text editor, which I used to do by adding a class to each field, but that meant putting js =('jsfiles.js') everywhere. I thought this would be a much cleaner method, as widgets can carry their own media files. Andrew. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---