Yes, another Django book i purchased. But this time not over Amazon, but direct from the publisher! Cheaper! Way Cheaper!
class Category(models.Model):
name = models.CharField(core=True, maxlength=200)
slug = models.SlugField(prepopulate_from=(’name’,))
parent = models.ForeignKey(’self’, blank=True, null=True, related_name=’child’)
description = models.TextField(blank=True,help_text=”Optional”)
class Admin:
list_display = (’name’, ‘_parents_repr’)
def __str__(self):
p_list = self._recurse_for_parents(self)
p_list.append(self.name)
return self.get_separator().join(p_list)
def get_absolute_url(self):
if self.parent_id:
return “/tag/%s/%s/” % (self.parent.slug, self.slug)
else:
return “/tag/%s/” % (self.slug)
def _recurse_for_parents(self, cat_obj):
p_list = []
if cat_obj.parent_id:
p = cat_obj.parent
p_list.append(p.name)
more = self._recurse_for_parents(p)
p_list.extend(more)
if cat_obj == self and p_list:
p_list.reverse()
return p_list
def get_separator(self):
return ‘ :: ‘
def _parents_repr(self):
p_list = self._recurse_for_parents(self)
return self.get_separator().join(p_list)
_parents_repr.short_description = [...]
If you would like to get some realtime Django help from the experts i recommend you have a look at the Django IRC channel. You can connect @
Django IRC Channel
Server Address: irc.freenode.net
Channel: #django
If you are new to Django i recommend that you also join #django-newbie
You can connect via a webbrowser if you couldn’t be bothered [...]
Up to Chapter 5 of this book. Already i know what the deal is with views, have made a full admin panel which error checks all entries, has categories, tagging and can generate HTML! Whoa! So good. Just notice that you may need to use SVN number 7966 and tagging r133 which can be [...]
It was this error that spent 2 hours of my day today:
ImportError: No module named coltrane
I had included my PythonPath entry manually into my MacOSX home directory via:
vi .profile
and entering:
export PYTHONPATH=/Users/myname/mydjangodirectory:$PYTHONPATH
This indeed works, but i was using a super user account to run all of my commands because i wanted the development web server to [...]
So if you are developing with Django and python you may be running off the Django SVN trunk. It can be a pain constantly running the update command when you simply want to be up with the development. Of course you would run this on a development server and not a production server! But i [...]
So i have been reading through the python and django books a bit more. The first one, Developing websites with Django was great, very project based, but it didn’t really go into the depth i needed in order to start programming my own websites. So i picked up my other book: