def get_parent(self):
if self.parent:
return [self.parent]
return []
def get_parent_tree(self):
asc = self.get_parent()
for p in asc:
asc.extend(p.get_parent())
return asc
This is what I use for generating a category crumb
hi Thomas,
thanks for all the details, actually my post was not really clear on
what I have.
the category model looks like this:
class Category(models.Model):
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
p
Hi,
Does this help you?
myslug=...
parents=[]
while myslug:
cat_crumb=Category.objects.get(slug=myslug) # I guess slug is unique
parents.append(cat_crumb)
myslug=cat_crumb.parent
But be careful, you might get infinite loops if the parent links
to a child. To avoid this you could write
sorry, had not finished this post before accidently submitting it...
for myslug not null
catcrumb_list = Category.objects.filter(slug=myslug)
myslug = catcrumb_list.parent
basically, I want to loop through the category model a parent is not
found, and each pass, store the model tupel in
4 matches
Mail list logo