I have a question, the functions like for example register user () must go inside the User class inside models.py or in the view.py?
Another question, how do I use a function of models.py from view.py?
I have a question, the functions like for example register user () must go inside the User class inside models.py or in the view.py?
Another question, how do I use a function of models.py from view.py?
It should go in your views, that is in views.py
. Ideally, according to several books about Django, is that in your models are the tables you will use and the logic of your business ( models.py
), in your file % admin.py
, should go everything related to the admin of Django , in your urls.py
all your urls of a specific app which is sent to call from the root folder of your project in your urls.py
file, all the forms in your forms.py
file, your unit tests from the file test.py
, 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 views.py
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
...
funcion_a_importar()
...