I decide to add a _pre_delete function to class Reporter that will
delete any articles for that Reporter before the Reporter is deleted.
Something like this...
def _pre_delete( self ):
articles = articles.get_list(reporter_id__exact=self.id)
for article in articles:
article.delete()
The problem is that this won't compile since articles is undefined.
What is the preferred way to deal with this type of forward reference
where the functions in a given class need to call functions defined for
a class that is itself defined later on in the same file?
def _pre_delete( self ):
articles = articles.get_list(reporter_id__exact=self.id)
for article in articles:
article.delete()
The problem is that this won't compile since articles is undefined.
What is the preferred way to deal with this type of forward reference
where the functions in a given class need to call functions defined for
a class that is itself defined later on in the same file?
Precisely what import statement would you use.
You will have to put thus inside the _pre_delete function, not at the
top of the module.
Luke
--
"My capacity for happiness you could fit into a matchbox without taking
out the matches first." (Marvin the paranoid android)
Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/
> Ahhh. That makes sense. Thanks!
footnote: also note that all uses of "articles" in the function refers
to the
same object, so your first line
articles = articles.get_list(reporter_id__exact=self.id)
replaces the module with a sequence. it doesn't matter in this
simple case, but may cause problems in larger examples. I'd
recommend something like:
article_list = articles.get_list(reporter_id__exact=self.id)
</F>
FWIW, if someone really wanted to implement _pre_delete for Reporter as
discussed, they should add this version of the function to class
Reporter:
def _pre_delete( self ):
for article in self.get_article_list():
article.delete()