user1746291
user1746291

Reputation: 333

Issues with models functions in django

I have made a function in models.py which do some mathematical calculations. Can i access this function from anywhere else like views or templates and feed some output to it and than modify the calculations of this function.

We can access the views functions or other functions in other files but i don,t know about models functions . If there is any way i can access them then Please suggest me some way to do this.

Thanks

Upvotes: 0

Views: 33

Answers (1)

Marat
Marat

Reputation: 15738

sure you can:

from my_app import models

output = models.my_function('foo', 'bar')

but.. don't you feel it's wrong? Semantically, models.py is for models. If you want an utility function, you can set up utils.py in your project and import from there. Otherwise, if this function is closely tied with a particular model, you can make it an object method instead, etc

Upvotes: 1

Related Questions