Hi Simon,
Ok - I checked that out, but I'm still unsure on something, in that
example you have self.thread within in the Reply save. I've tried
applying the same way to my model like this:
def save(self):
if not self.slug:
self.slug = slugify(self.title)
super(Leaf, self).save()
self.branch.num_leafs = self.branch.leaf_set.count()
self.branch.save()
def delete(self):
super(Leaf, self).delete()
self.branch.num_leafs = self.branch.leaf_set.count()
self.branch.save()
However, 'Leaf' object has no attribute 'branch' is the error I get.
I'm assuming i probably need to set self.branch, I tried this:
self.branch = Branch(pk = self.content_type)
however I get this error: Incorrect integer value: 'Pages' for column
'content_type_id' at row 1, so obviously it's passing in the text
version of content type, and not the id. Any ideas?
On Dec 1, 2007 3:15 AM, Simon Willison <[EMAIL PROTECTED]> wrote:
>
> On Nov 30, 4:48 pm, "Tane Piper" <[EMAIL PROTECTED]>
> wrote:
> > As you can see in the Branch model, there is a field called num_leafs
> > - I've been reading the signals documentation and had a look on the
> > web, but I'm still having difficulty getting my head around it. What
> > I want to do is when a leaf is saved, on the post_save signal I want
> > to increment the parent branch's num_leafs field so it contains total
> > number of content leafs for that branch (as a counter cache).
>
> This exact example was covered in the Advanced Django Tutorial at
> OSCON this year (in the unit testing section) - you may find the
> slides from the tutorial useful:
>
> http://toys.jacobian.org/presentations/2007/oscon/tutorial/
>
> Cheers,
>
> Simon
> >
>
--
Tane Piper
Blog - http://digitalspaghetti.me.uk
AJAX Pastebin - http://pastemonkey.org
This email is: [ ] blogable [ x ] ask first [ ] private
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---