I am attempting to create a web app which is basically a pretty frontend to a database. While the database is more complicated than a single table (many different relations to many different tables and such), I would like to create a blank rows when adding to one of the main tables.
I'm curious if there is a better way of completing my task in Django than what I am attempting to use.
I don't want a user to need to save their form for changes to be saved to the database. To do this I was hoping to have a blank record created as soon as the user visited the page with the form on it. Basically all that would exist as soon as the user selects the "new" button would be a record with a primary key, and a bunch of blank fields.
I have set up my model to have blank=True and null=True on all fields except the date fields (which are set using auto_now_add). As a user adds data to form fields I intend to have the form programmatically scripted to submit data (ie after they leave a field). Should the user stop editing half way, or close the jquery ui tab, any data they entered will be saved for their future use.
Despite having set all fields (again except the auto_now_add for the date and time fields), I am getting an IntegrityError (cannot be null) on a field which is very clearly marked as very much null and blank happy in the Model. Is there a better way I should be going about this? If not, why might I be seeing this error when I have null=True and blank=True set? I am receiving the error because of the following line in a view, for again, a field which is null=True and blank=True in the Model.
theModel = theModel.obje开发者_JAVA百科cts.create()
Thanks much.
It doesn't matter what your model says, only what the database says. Since syncdb does not modify the schema you will either have to apply the changes yourself, use a migration tool such as South, or drop the table altogether and resync.
精彩评论