Django - View - Model


I have a question, the functions like for example register user () must go inside the User class inside or in the

Another question, how do I use a function of from

asked by user6905478 07.10.2016 в 23:45

1 answer


It should go in your views, that is in . Ideally, according to several books about Django, is that in your models are the tables you will use and the logic of your business ( ), in your file % , should go everything related to the admin of Django , in your all your urls of a specific app which is sent to call from the root folder of your project in your file, all the forms in your file, your unit tests from the file , and the rest as you see, middlewares, utils, resources, backends, etc ...

Regarding your other question, if the function does not belong to a class, that is, it is not a method, or a static method, you can simply import it as you normally would.

In your file:

# en caso que estes posicionado en la misma carpeta que models
from .models import funcion_a_importar
# de lo contrario
from myotherapp.models import funcion_a_importar

# y puedes usarla cuando quieras
answered by 07.10.2016 в 23:52