Django - manage.py sql APPNAME not generating model SQL

前端 未结 2 659
小蘑菇
小蘑菇 2021-01-25 06:13

I have a relatively large flat application that I\'m working on. To maintain separation of concerns, I\'ve split the model and view files into auth_models, d

2条回答
  •  爱一瞬间的悲伤
    2021-01-25 06:47

    If your auth_models.py contains a model class MyUserModel, you need to put the following in the __init__.py under app/models:

    try:
        from .auth_models import MyUserModel
    except ImportError as e:
        sys.stderr.write("Error: failed to import models module ({})".format(e))
    

    P.S. Another suggestion would be to improve the style you name your files with. Since auth_models.py, dashboard_models.py and taxonomy_models.py are all under app/models you can simply truncate the _models.py ending. I.e. rename your files under /models:

    auth_models.py -> auth.py
    dashboard_models.py -> dashboard.py
    taxonomy_models.py -> taxonomy.py
    

    To import the Model classes as instructed above:

    from .auth import MyUserModel
    

提交回复
热议问题