Pages

Saturday, March 16, 2013

You should always issue a redirect for successful POST requests


The reason: if a user hits “Refresh” on a page that was loaded via POST, that request will be repeated. This can often lead to undesired behavior, such as a duplicate record being added to the database – or, in our example, the e-mail being sent twice. If the user is redirected to another page after the POST, then there’s no chance of repeating the request.
You should always issue a redirect for successful POST requests. It’s a Web development best practice.

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
from mysite.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 thedef __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