Hi there.
supposed you've got a nested model like this:
class Article(models.Model):

    parent_article = models.OneToOneField("self", blank=True, null=True, 
default=None, related_name="child_article")

How would you traverse the related model chain ( aka linked list ) to one 
end?
Maybe with a generator that makes you a nice list, that can be printed:
def article_child_gen(article):
    yield article.child_article
    while True:
        yield from article_child_gen(article.child_article)
This throws an exception if it reaches the end. You catch it and return. 
Great. In theory. The problem is that its not easy to catch it, because you 
are not allowed to catch it.
It's name is RelatedObjectDoesNotExist, defined by 
SingleRelatedObjectDescriptor in django.db.models.fields.related . So my 
question is: is there a way to catch this anyway, or to get around it? 
Because the other path that i am going now is to 
Article.objects.filter(parent_article=blabla) me through this problem. But 
this just doesn't seem to be a clean solution.
thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9c5decd8-c90c-41e1-9ce4-c64c26cb1dce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to