For the code at the bottom of page 69 to work you need to make sure you have you are import the coltrane Entry model in the urls.py file of the cms app which you should have created in the previous chapter.
Posts Tagged ‘errata’
Practical Django Projects. Page 69 Errata : Missing import statement
Saturday, January 10th, 2009Practical Django Projects. Page 60 Errata
Thursday, January 8th, 2009The import command will not work because whoever packaged this application forgot to add the file __init__.py which is what tells python that the folder should be treated as a module. After you add an empty file named __init__.py everything should work as expected.
Also the following 2 lines of code are incorrect:
self.body_html = markdown(self.body) self.excerpt_html = markdown(self.excerpt)
The problem is that the folder module is called markdown, and then the file that contains the class is called markdown, and the class we need is called Markdown, notice capital M.
Assuming we want to use the import statement as specified in the book, the 2 lines of code above need be changed to:
self.body_html = markdown.Markdown(self.body).convert() self.excerpt_html = markdown.Markdown(self.excerpt).convert()
Practical Django Projects. Pages 63,64 Errata
Thursday, January 8th, 2009The code on these pages will obviously not work as is. If you don’t know why, please read my previous posts.
I will not post how the code should look like, as you should have the correct code if you have been following the posts.
Practical Django Projects. Page 51,54 Errata
Thursday, January 8th, 2009The prepopulate_attribute should be removed from the definition of the slug fields. That option should be in the admin class of the model. See previous posts to know more.
Practical Django Projects. Page 50 Errata
Thursday, January 8th, 2009The following line of code is no longer correct:
slug = models.SlugField(prepopulate_form=['title'],unique=True)
Because the prepopulate_form attribute is something that only has meaning within the admin app, it now has to be put in the admin.py file. Assuming you have read the previous post, the content of admin.py should be the following:
from django.contrib import admin
from coltrane.models import Category
class CategoryAdmin(admin.ModelAdmin):
model = Category
prepopulated_fields = {
"slug" : ("title",)
}
admin.site.register(Category,CategoryAdmin)
Practical Django Projects. Page 47 Errata
Thursday, January 8th, 2009The Category model is using the old way of telling the admin app to include it in the admin section. Read this to know more.
If you have read the previous posts you should be able to know by now what is wrong and how to correct it. But in case you don’t, here is what you need to change to make it work:
1. Delete the following 2 lines:
class Admin:
pass
2. Go to the folder where you added the models.py file(If you are following the book verbatim it should be named coltrane), create a file called admin.py and the following code to it:
from django.contrib import admin from coltrane.models import Category admin.site.register(Category)
Spoiler: You will have to change the code above to include other options before the chapter is over
Practical Django Projects. Page 34 Errata
Sunday, January 4th, 2009The code for the model SearchKeyword, which is just introduced on page 34, needs to be changed to account for the decoupling of model and admin definitation that happened on Django 1.0.
Eventhough it was very easy before, Django 1.0, to tell the admin app that you wanted it to generate an admin interface for a model it was pretty ugly. The new way takes a couple more steps at the beginning but I believe in the long run it has a lot of benefits besides that given one of decoupling.
First get rid of the following lines from search/models.py:
class Admin:
pass
then, navigate to the folder cms/search which you should have created if you followed the steps verbatim, create a file called admin.py and add the following to it:
from cms.search.models import SearchKeyword from django.contrib import admin admin.site.register(SearchKeyword)
Save the file, restart the django webserver and you should see a new group on the admin section for the search app.
HTH
Reading Practical Django Projects
Sunday, January 4th, 2009I decided to polish my django knowledge, so I bought the book “Practical Django Projects”( I also bought Professional Django but that is another post). I just finished Chapter 3 and I can tell you that there is going to be a lot of code in the book that will no longer run. It seems that when the book was written the latest Django version was 0.96 and a lot of things have changes since. I will be making a post for each chapter that I find with problems where I will provide code that, hopefully, works.
BTW, This is my first blog post.