You can define a value for the model's field by using the commit=False
"trick".

myform.save(commit=False) returns an instance of the model which hasn't yet
been saved to the database. So you can manually set the value for any
additional fields and then call save on the object to finally write it to
the db.

Please see the official docs[1] for futher reference.

In the future, try to pick a subject for your e-mail that explicitly states
the problem. Something like "hi" will get ignored most of the time!


Sincerely,
André Terra

[1]
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method


On Mon, May 23, 2011 at 11:01 AM, William Hudspeth
<bhudsp...@edac.unm.edu>wrote:

> hi
>
> On Tue, 2011-05-10 at 09:08 -0700, wilbur wrote:
> > I am using Django 1.2.4 with a Postgresql 8.4 backend. Before creating
> > my models in Django, I began with a existing Postgresql database with
> > tables for which I had defined integer primary keys that used an
> > autoincrementing sequence on table inserts. When I created my Django
> > models, I defined the primary keys as IntegerFields with primaryKey
> > set to true using the same primary key field names as in the pre-
> > existing database tables.
> >
> > This autoincremented variable set in postgresql is
> > visible in the Django admin as "Sample_ID", with an empty form field.
> > Because the user can't possibly know what the next value in the
> > sequence
> > should be, I'm wondering how to deal with the field, as it is Not
> > NULL, and any attempt to submit without a value returns an error. Is
> > there perhaps a way to make the field not visible in admin, but have
> > the field automatically filled in once the rest of the form fields are
> > submitted?
> >
>
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to