class Category(models.Model):
    parent = models.ForeignKey('self', null=True, related_name='children',
        related_query_name='child')
Category.objects.filter(child__isnull=True)
Django: Query self referencing objects with no child elements