The few times that I have seen this error in my own code, finding the source and squashing any related bugs was pretty easy. For the first time today, I saw it appear when I was using the provided admin interface to add a user to my project where I was using django.contrib.auth. It caused me to panic a little.
With a little bit of google searching, I found this post on the django google group that helped me fix my problem clearly and quickly.
I am using a postgres back end, and it seems like the counter for the serial field was reset. By looking at the table and finding which value should come next, I was able to set this counter to the proper value, and so far everything is working great.
Showing posts with label django. Show all posts
Showing posts with label django. Show all posts
Tuesday, May 31, 2011
Friday, October 16, 2009
First apps and models are validated!
My very first apps and models have been validated. I could have saved a lot of frustration had I only read through the entire tutorial. So, the moral of the story is, RTFM.
Specifically, I needed to use functions that are included as part of manage.py, and not try to make any glue myself.
I will add to this post, on Monday, with details on how exactly I got my first Django project started.
Thursday, October 15, 2009
Django - Design Your Model
The first step that I'm going to take to designing my web app is to start building up the model. Reference for this section starts with the Design Your Model section of the Django overview, and also the related section Data-Model Syntax.
The model is one of three parts that build up the Model-View-Controller architectural pattern. Basically, the model is a description of your data. Let's say you're designing a social networking application. In plain English, your model would start off something like, "The basic unit of data that we are working with is a member of the site. A member has a first name, last name, password and chosen user name. Members are related to other members in a many-to-many relationship. Members can be friends with other members, they can ignore other members, etc. By default, a member's list of friends is sorted by the order in which they were added..." and your model would continue. The formal model is nothing more than a translation of this natural language model into python.
The view component of an MVC web app tells the browser how pages are displayed. Mostly, the view is made up of templates that have components of the model plugged in.
The controller of an MVC web app handles page requests and decides what to do with components of the model. For example, if you went to visit the home page of our social networking example, it would check to see if you had an existing session, and if not, it will grab a log in page provided by the view. After a user enters this info, the controller takes care of several steps:
- It attempts to authenticate the user against existing users in the database
- If authentication is successful, it grabs the appropriate components of the model
- It plugs those components into a template provided by the view
- It sends the template, complete with info composed from the database, to the user's browser.
Armed with this information, I am going to begin writing parts of the model, and then write some python scripts to import my existing data into my Django web app.
For further reference, see Interacting with a Database: Models from Definitive Guide to Django; however, please note that, although this text is less than two years old, different versions of Django can change dramatically. The most up-to-date reference is always available at http://www.djangoproject.com/.
Subscribe to:
Posts (Atom)