This field is required. NO!

1 view
Skip to first unread message

Andre Meyer

unread,
May 16, 2008, 8:06:32 AM5/16/08
to django-users
hi all

now, this is driving me crazy. this problem persists even after switching from 0.96.1 to the newforms-admin branch.

after declaring a model class with an attribute that may be null (pn) the admin site still tells me to fill in that field, because "This field is required.", but it isn't.

i have registered the model class to the admin site without any custom options.

recreated the database file (sqlite) after switching to the na branch.

checked in SQLite Manager that the pn field may indeed be null.

new Dossier instances can be created and saved in the shell without the pn attribute, but when viewing the instance on the admin page and pressing Save, the error appears.

what is the matter?????

thanks for your suggestions
cheers
André


code:

model.py

class Dossier(models.Model):
    an = models.CharField('Dossier number', max_length=10, primary_key=True)
    pn = models.CharField('Publication number', max_length=20, null=True)

    def __unicode__(self):
        return self.an

admin.site.register(Dossier)

Almir Karic

unread,
May 16, 2008, 8:10:07 AM5/16/08
to django...@googlegroups.com
On Fri, May 16, 2008 at 2:06 PM, Andre Meyer <andre....@gmail.com> wrote:
> pn = models.CharField('Publication number', max_length=20, null=True)

missing a 'blank=True'

--
For far too long, power has been concentrated in the hands of "root"
and his "wheel" oligarchy. We have instituted a dictatorship of the
users. All system administration functions will be handled by the
People's Committee for Democratically Organizing the System (PC-DOS).

Scott Moonen

unread,
May 16, 2008, 8:10:17 AM5/16/08
to django...@googlegroups.com
Andre, in addition to saying null=True, try adding blank=True.

  -- Scott
--
http://scott.andstuff.org/ | http://truthadorned.org/

Jarek Zgoda

unread,
May 16, 2008, 8:12:39 AM5/16/08
to django...@googlegroups.com
Andre Meyer pisze:

> now, this is driving me crazy. this problem persists even after
> switching from 0.96.1 to the newforms-admin branch.
>
> after declaring a model class with an attribute that may be null (pn)
> the admin site still tells me to fill in that field, because "This field
> is required.", but it isn't.
>
> i have registered the model class to the admin site without any custom
> options.
>
> recreated the database file (sqlite) after switching to the na branch.
>
> checked in SQLite Manager that the pn field may indeed be null.
>
> new Dossier instances can be created and saved in the shell without the
> pn attribute, but when viewing the instance on the admin page and
> pressing Save, the error appears.
>
> what is the matter?????

http://www.b-list.org/weblog/2006/jun/28/django-tips-difference-between-blank-and-null/

--
Jarek Zgoda
Skype: jzgoda | GTalk: zg...@jabber.aster.pl | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

Kenneth Gonsalves

unread,
May 16, 2008, 8:17:38 AM5/16/08
to django...@googlegroups.com

On 16-May-08, at 5:36 PM, Andre Meyer wrote:

> after declaring a model class with an attribute that may be null
> (pn) the admin site still tells me to fill in that field, because
> "This field is required.", but it isn't.

have you set blank=True?

--

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/

Ben Ford

unread,
May 16, 2008, 7:10:06 AM5/16/08
to django...@googlegroups.com
Andre,

You also need blank=True here:


pn = models.CharField('Publication number', max_length=20, null=True)


That will fix you :-)
Ben


Andre Meyer wrote:
> hi all
>
> now, this is driving me crazy. this problem persists even after
> switching from 0.96.1 to the newforms-admin branch.
>
> after declaring a model class with an attribute that may be null (pn)
> the admin site still tells me to fill in that field, because "This
> field is required.", but it isn't.
>
> i have registered the model class to the admin site without any custom
> options.
>
> recreated the database file (sqlite) after switching to the na branch.
>
> checked in SQLite Manager that the pn field may indeed be null.
>
> new Dossier instances can be created and saved in the shell without
> the pn attribute, but when viewing the instance on the admin page and
> pressing Save, the error appears.
>
> what is the matter?????
>
> thanks for your suggestions
> cheers
> André
>
>
> code:
>

> /model.py
> /


> class Dossier(models.Model):
> an = models.CharField('Dossier number', max_length=10,
> primary_key=True)
> pn = models.CharField('Publication number', max_length=20, null=True)
>
> def __unicode__(self):

> return self.an <http://self.an>
>
> admin.site.register(Dossier)
>
>
> >

Andre Meyer

unread,
May 16, 2008, 8:18:21 AM5/16/08
to django...@googlegroups.com
oh dear, this seems to be a well-known thing.

thanks so much for this, it works!

still need to figure out why ;-)

thanks to you all
André

Kenneth Gonsalves

unread,
May 16, 2008, 8:32:40 AM5/16/08
to django...@googlegroups.com

On 16-May-08, at 5:48 PM, Andre Meyer wrote:

> still need to figure out why ;-)

by default, django treats all fields as not null and not blank.
Usually, the 'null' part is enforced at the database level and the
'blank' part at django level. So for fields like CharFields, saying
null is allowed is not the same as saying blank is allowed.

Reply all
Reply to author
Forward
0 new messages