开发者

ImportError importing forms.py into models.py

I would really like to make a form instance a model attribute so that i have access to the form from the template through a开发者_如何学Gon object that I have handy.

When I try to import import any form into models.py, I get an ImportError on each of the import statements in the forms.py file which reference a model in models.py. I'm assuming this is due to circular imports.

I can't seem to find any information on importing forms into models. Is this possible? If so, how?


What you're doing doesn't sound right, but if you want to do it you can embed the form import in the models' instance method like so:

class TestModel(model.Models):
    def get_my_form(self):
        from my_app.forms import MyForm
        return MyForm()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜