On 2/3/06, sam <[EMAIL PROTECTED]> wrote:
You have to use self.bar to refer to bar defined in the same class.
You will have to import that module in the function where you intend to call it. You can also use module constants, refer http://www.djangoproject.com/documentation/model_api/
I was tring to write a custom function inside a mode class, say X:
class X(meta.Model):
i = meta.IntegerField()
...
def foo(self):
return bar(self.i)
If I define bar() in the same model file, django complained the
"NameError -- global name bar does not exist". How do I get around
this?
You have to use self.bar to refer to bar defined in the same class.
What if I want to define bar() in another file under the same
app/models directory -- how do I refer it in my model file?
You will have to import that module in the function where you intend to call it. You can also use module constants, refer http://www.djangoproject.com/documentation/model_api/
--
Amit Upadhyay
Blog: http://www.rootshell.be/~upadhyay
+91-9867-359-701

