Hi there, At the moment, I am building my site content system. The idea is that categories are branches, and contents are leafs as defined by these two models below:
from django.db import models from django.contrib.auth.models import User from django.contrib.auth.decorators import permission_required from django.template.defaultfilters import slugify from django.utils.translation import gettext_lazy as _ import datetime PUBLISHED_CHOICES = ( (0, 'Draft'), (1, 'Pending Review'), (2, 'Published'), (3, 'Archived'), ) class Branch(models.Model): parent_id=models.IntegerField(max_length=11) title=models.CharField(max_length=100) active=models.BooleanField() generate_feed=models.BooleanField() num_leafs=models.IntegerField(default=0) def save(self): self.slug = slugify(self.title) super(Branch, self).save() def __unicode__(self): return self.title class Admin: pass # Create your models here. class Leaf(models.Model): title=models.CharField(_('Title'), max_length=200) body=models.TextField(_('Body')) user=models.ForeignKey(User) pub_date=models.DateTimeField('date published') num_comments=models.IntegerField(default=0) num_views=models.IntegerField(default=0) published=models.IntegerField(max_length=1, choices=PUBLISHED_CHOICES) front_page=models.BooleanField() sticky=models.BooleanField() allow_comments=models.BooleanField() content_type=models.ForeignKey(Branch) def save(self): self.slug = slugify(self.title) super(Leaf, self).save() def __unicode(self): return self.title class Admin: pass 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). I also need to go reduced it by one each time a leaf is removed. If I could get some help with this first one (which I was able to implement easily in PHP but just cannot translate to Django) I think I'll be fine. -- 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 django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---