Saturday, March 16, 2013
blank=True null=True
So that’s a long way of saying this: if you want to allow blank values in a date field (e.g., DateField, TimeField,DateTimeField) or numeric field (e.g., IntegerField, DecimalField, FloatField), you’ll need to use bothnull=True and blank=True.
Friday, March 15, 2013
Adding your models to the Admin Interface
from django.contrib import admin frommysite.books.models import Publisher, Author, Book admin.site.register(Publisher) admin.site.register(Author) admin.site.register(Book)
Indent error def __unicode__(self):
Your exact indentation you've pasted wouldn't throw that error, but in your real code, you must have the
def __unicode__ line at the exact indent depth as the other lines in your model.
Make sure you are using spaces and not tabs for all of your indents, as tabs can sometimes make the indent level seem the same as the others.
No module named books
Thanks for the help everyone. I was using 1.4.x, not the 1.0 the book is based on. After fooling around with the commands for a bit, I was able to figure out that the problem was in the INSTALLED_APPS section - I included 'mysite.books', but the new way to do that is just 'books'.
Instead of mysite.books in the INSTALLED_APPS write books
Instead of mysite.books in the INSTALLED_APPS write books
sqlite3.OperationalError: unable to open database file
I'm a beginner, too, and had a similar problem. The .db file will created for you when you run
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydata.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Database will be created once you do python manage.py syncdb
Finally to check if everything is fine
from django.db import connection
cursor = connection.cursor()
If nothing happens, then your database is configured properly. Otherwise, check the error message for clues about what's wrong.
python manage.py syncdb. From your terminal window, just be sure that you're located in the same folder as the manage.py file in your directory structure. From this location, I was able to successfully create the necessary tables. The settings.py file will have already been created when you initially set the project up.DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydata.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Database will be created once you do python manage.py syncdb
Finally to check if everything is fine
from django.db import connection
cursor = connection.cursor()
If nothing happens, then your database is configured properly. Otherwise, check the error message for clues about what's wrong.
Subscribe to:
Posts (Atom)