Initial thoughts on Django
Most of the Python apps I’ve written have used Flask, and that is mostly because I do more than just web apps. At work we’ve recently been refactoring and breaking apart a part of one system, and the decision was to use Django.
My first hesitation in learning a new framework was the time needed for me to pick up, and there was also the Django ORM vs SQLAlchemy. I had never really thought too much about different ORM designs and differences until very recently, and with it came many opinions. I’ve been jotting down quick notes whenever I remember, and here are some of them.
Django notes #
- lack of PostgreSQL features in terms of daterange filtering max(upper(daterange)) query seems like it is too much work to do
- ORM is a bit inflexible once you get a bit used to using powerful features of PostgreSQL, like views and window aggregation within SQL
- a bit of hackery to map a view to a ORM model, but possible
- not sure what is the best way to test database tables that aren’t mapped to a model within the ORM, or tests that query another database
- ORM is good at keeping track of migrations and making sure you’re tidy
- testing suite is very good, makes for good TDD
- organisational structure is good, framework makes it easy to organise the project
- takes a bit of getting used to how to query within the ORM (fields? joins? attributes?) active record pattern vs unit of work
- all the configs and WSGI stuff handled pretty well
- contrib.auth and contrib.contenttypes lets you manage authentication and permissions associated with created models
As you can see, a lot of my issues come from being used to SQLAlchemy and how flexible it is. But using Django has made me realise that it was built with CRUD web apps in mind, and for that it is really powerful. The nature of my previous work involved dealing with complex data driven applications, ones where they do not fit into any specific design mold. This is the main reason why I haven’t done anything serious in Django.
After about a month of usage, I’m still not sure how I feel about Django vs Flask for anything other than stock CRUD apps.