Problem when importing model

Asked

Viewed 430 times

0

Hello, I’m not getting the import of this model

have the model:

class Contrato(models.Model):

within models.py

and inside my serializers.py need to do import

from models import Contrato

nor

from apps.contratos.models import Contrato

Nothing works, other apps work smoothly.

  • Pass only app and model from myapp.models import Contrato

  • Check your PYTHONPATH, the import path needs to be found relative to it. If the folder apps is on PYTHONPATH, so from contratos.models import Contrato should work.

3 answers

0

The text of the question could be a little more complete and provide the traceback of error. However, without knowing the structure of the project, the problem may be that the directory where both these files are located does not contain the file __init__.py ( see why ).

If that file is present, the following line should be sufficient to successfully import:

from .models import Contrato

0


It was taking place an import loop, they were caring for each other. Solved, I just removed the import of one of the files and it worked.

0

If your serializer file is in the same module as your model, a way to import: from .models import Contrato

Browser other questions tagged

You are not signed in. Login or sign up in order to post.