News for hackers. Stuff that matters.
Re:Ask HN: What web framework do you use? Why did you choose... by shashwat986 on Monday December 26, 2016 @01:16AM (#13257220)
I've always been curious as to how you structure your models in Django.

I'm building a personal project in Tornado and MongoExpress, and the only thing I can see about structuring my models is to put all of them in one file called models.py

I'm used to the RoR way of doing things, so this seems very counter-intuitive to me.

In addition, whenever I try to break the classes into different files, I'm not sure of where to store my DB connection logic, and how to ensure that all models are accessible from the controllers.

Ideas?

Re:Ask HN: What web framework do you use? Why did you choose... by akx on Monday December 26, 2016 @02:02AM (#13257306)
You can make `models` a package, where `models/__init__.py` just imports models from the package's modules (`models/thingamabobs.py` and ` from .thingamabobs import Thingamabob`).

Also, you shouldn't need to worry about database connection logic in Django unless you're doing something very specific.

Re:Ask HN: What web framework do you use? Why did you choose... by spapas82 on Monday December 26, 2016 @04:43AM (#13257651)
Depending on the situation, I think it's usually better to seperate the models to different apps instead of using a single app with a models.py-package. This way you'll have seperate views, forms, urls, admin, templates etc.

For common functionality (ie an abstract model or a mixin that is used/inherited by multiple models/views) I like to add another django app named common or core that is used by the other apps.

Re:Ask HN: What web framework do you use? Why did you choose... by shashwat986 on Monday December 26, 2016 @12:06PM (#13258884)
I'm using Tornado, not Django. I just want to use Django as an inspiration for my app structure.

The problem with Tornado is that it doesn't come with an in-built ORM like Django, which means I need to actually create a connection to the Mongo instance I'm using. Hence the confusion. Python doesn't have initializers like Ruby does (that I know of).