Hi all,
I'm having problems structuring classes in the Model part of an MVC pattern in my Python app. No matter how I turn things, I keep running into circular imports. Here's what I have:
Model/__init__p.y
- should hold all Model class names so I can do a "from Model import User" e.g. from a Controller or a unit test case
Model/Database.py
- holds Database class
- needs to import all Model classes to do ORM
- initialization should be performed on first module import, i.e. no extra init calls or instantiations (all methods on Database class are @classmethods)
Model/User.py
- contains User model class
- needs access to Database class to do queries
- should inherit from base class common to all Model classes to share functionality (database persistency methods, parameter validation code etc.)
I have yet to see a real world Python app employing MVC, so my approach is probably un-Pythonic (and possibly a language-agnostic mess on top of that...) - any suggestions on how to solve this?
Thanks, Simon