Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

78% Positive

Analyzed from 1546 words in the discussion.

Trending Topics

#django#having#orm#easy#python#things#why#project#https#queries

Discussion (37 Comments)Read Original on HackerNews

matsemann•about 1 hour ago
I really like the ORM and the migrations, but some parts I really dislike. They're maybe not Django's fault, but how it's used most places:

* Models being passed around everywhere, queries happening everywhere. I prefer having a dedicated service/selector layer to do those things. Then convert to pydantic objects or something that's passed around further.

* Corollary, but adding stuff to querymanagers quickly goes out of control. Sure, it's nice to reuse MyModel.objects.annotate_something().annotate_something_else().... but it can quickly become unwieldy and even wrong with exploding joins. And it promotes doing queries in places they shouldn't happen.

* It's veeery easy to make spaghetti. Very easy to query across boundaries, into other apps. Fine on smaller projects, but in huge codebases it quickly makes things hard to control, especially since it's all stringly typed. If I want to modify my model, it's hard to know if someone else have done a query where they did theirmodel__some_relation__another_relation__mymodel__some_field. Blows up in production.

* For some reason it's very common in Django/python projects to have types.py, models.py, selectors.py, views.py, services.py etc. And then each of those end up with lots of unrelated things in the same python file, while related stuff is spread over many files. Django apps doesn't really solve this cleanly either.

kitsune_•21 minutes ago
The ORM is really not good in my opinion because it is ActiveRecord'ish and has all its downsides. I wouldn't use Django for any moderately complex domain. But even with simpler CRUD style apps I don't really see the point in it.
DarkNova6•about 1 hour ago
I seriously don't get why Django ORM is using the Active Record pattern. This is such a stupid footgun that trivially causes horrible performance and BEGS you to cause n+1 problems.

Never in my life did I have a problem with lazy loading causing unbearable performance until I joined a Python Django team. I really tried to find sympathy for the "dynamically typed" folks (please spare me saying Python is technically statically typed), but coming from writing apps and backends in Java, Swift, C#, Objective-C and PHP, Python with Django was the worst experience bar none.

I worked on the project for 10 months, could at least refactor the project to something semi-sane where obvious mistakes (which would not be possible in other languages) could not happen. Then along comes a "good Python dev" and threw it all out of the window and start doing SQL queries all over the place (typically 3-6 lines long), remove the domain objects and cause the same problems I started with to begin with. But his approach was saying that the other developers were "not good enough".

Yeah, have fun with schema changes going forward. Good riddance.

senko•22 minutes ago
Yes, if you attempt to use Django like you'd use your typical Java, Swift, C#, or Objective-C framework, you're not going to have a good time.

I've seen the horrors Java devs start doing on a Python project when trying to "fix" things, where by "fix" they mean use patterns they had to in previous gigs.

It's a different world.

DarkNova6•14 minutes ago
Having basic defensive programming, some simple classes instead of dicts everywhere and avoiding n+1 is a "different world"?
JodieBenitez•25 minutes ago
> BEGS you to cause n+1 problems

select_related, prefetch_related. n+1 problems be gone.

DarkNova6•17 minutes ago
You misunderstand. And that is exactly the problem.

We did do that and that's why our queries ended up being several lines long. But if you missed just one model? You openly walk a knife again.

It's a mess and it only gets longer and longer. I ended the project with having some proper aggregates, only for that to be thrown out of the window by the guy after me.

Oxodao•32 minutes ago
I despise django-orm, doctrine is so much better. Like, who thought that using named arguments to do stuff was a proper way ??? `.filter(created_at__gte=XXXXX)` why? The rest of the framework is great but the ORM is definetly its weakest point.
zelphirkalt•14 minutes ago
I find those double underscore kwargs weird too, and would prefer to simply pass a lambda instead. What is your idea, what would you suggest?
JodieBenitez•24 minutes ago
Having used Doctrine, hard disagree. Never again.
zelphirkalt•18 minutes ago
What I like about Django are the following things:

(1) It seems whenever I need to adjust how something works, there is some field or method, that I can override, or meta class attribute to set. None of it seems too inflexible. Overriding or changing how things work somehow always feels like someone already thought of this special case I have, and has made it mostly easy to do. Often when I have such a customization case, I have this feeling: "AH, that's how it is supposed to be done in Django." instead of having a feeling of having to fight the framework.

(2) Just being able to use a normal template engine (I always use Jinja2 with Django), instead of having some wannabe HTML lookalike thing. I don't want to have to encode control flow inside HTML attributes. Why then make it look like HTML in the first place, if some JS framework then picks it apart? It is unnecessarily cumbersome to do that, and Django doesn't engage in that.

(3) The ORM is good, and flexible. Some traps for many queries though. But also escape hatches, which let one write ORM calls, that will translate to efficient SQL in most cases.

(4) Django makes it so easy (comparatively) to write a phenomenal searching and ranking function for ones database entities. Check for example the code of my blog [1]. One page of code, very adjustable to ones needs.

(5) Handling of routes is easy. `reverse` is very useful to not have to hardcode routes.

(6) Even when using third-party things like django-allauth it is easy to override templates, without having to modify the dependency itself. With foresight there exists a way to put ones own templates in a place that is discovered before the other package's templates.

(7) Adjustable django admin. I often have some "Tags" in my models, which are many-to-many. For example Posts-TagAssignment-Tag, where TagAssignment is a "throught table". In Django admin one can have a nice little modification [2] to make a very usable widget appear for assigning tags.

In short: It very much gets out of ones way.

[1]: https://codeberg.org/ZelphirKaltstahl/django-website/src/com...

[2]: https://codeberg.org/ZelphirKaltstahl/django-website/src/com...

saaspirant•43 minutes ago
Django for Startup Founders: A better software architecture for SaaS startups and consumer apps: https://web.archive.org/web/20210624040717/https://alexkrupp...

This article is very useful.

I use DRF but not serializers and write validations by hand because it is too abstract for me.

My views just call services and return the result.

stuaxo•about 2 hours ago
Nice.

I've been meaning to do my own Django post, on some other bits we take for granted - I should do it.

People should be using Django, the best parts are so useful you don't notice them until you switch platforms and implement them badly.

Every app that used a more narrow solution ultimately ends up implementing parts of Django badly.

The best way to solve this from Djangos side would be to have official ways of:

- Using the ORM outside of Django - Doing single file Django apps

Both of these have various 3rd party solutions, which shows demand.

In the past other bits of Django have been split off by 3rd parties but those two are the places to start.

JodieBenitez•about 2 hours ago
Most loved feature, for me: No dramatic changes, just sane and careful evolution.
whateverboat•43 minutes ago
I really like django, but since being involved in it from early days, whenever someone now praises Django, I am reminded of this talk: https://www.youtube.com/watch?v=i6Fr65PFqfk

DjangoCon 2008 Keynote: Cal Henderson

vb-8448•41 minutes ago
what's wrong nowadays w/ django?
harrouet•about 1 hour ago
Ah the old debate about function-based views and class-based views.

I totally understand why the OP would use only FBV, however when writing REST APIs you will want CBV to reuse base classes such as ListView.

tinodb•about 1 hour ago
> 3. Actions

It is somewhat explained as a convention or something built-in, but I can't find much about it elsewhere. Is it the author's own convention or am I missing something?

jbarham•40 minutes ago
Yeah, I wondered about that too as normally Django "actions" mean admin actions (https://docs.djangoproject.com/en/dev/ref/contrib/admin/acti...). But in this case it seems the blog post is referring to this pattern: https://www.jmduke.com/posts/in-praise-of-actions.html (same author)
Klonoar•about 1 hour ago
I feel sufficiently old after having read South in this article. Good god what a throwback.

Django is hands down one of my favorite frameworks ever created, and the only one I still reach for in some contexts. For a lot of projects I use it to drive database migrations, and stand up an easy admin portal for others to use - then anything else is driven by an API layer written in (e.g) Rust.

I haven't had to care about Django's performance in years but still get to reap some of the benefits.

sinpif•40 minutes ago
Migration churn adds up over the years but overall it's nice and site-specific code is usually so small it fits very nice in LLM context.. easy to work with.
0x4d4c•about 1 hour ago
I remember, when I used it for the very first time in commercial project. Client briefed me in the afternoon, the next day, before the noon, she got ugly app, but with fully working admin backend. She was sold.

But I also remember, that some non-standard requirements were really difficult to implement or get around.

Having that in mind, the next project was entirely in Pylons. All was good, until we were asked to add Unicode support.

Since them I'm on Rails.

thraxil•25 minutes ago
> Having that in mind, the next project was entirely in Pylons. All was good, until we were asked to add Unicode support.

How long ago was this? I feel like unicode has kind of been a solved problem in Python since python3 came out. In the python2 days it was, indeed, miserable.

Advertisement
tonyedgecombe•about 2 hours ago
I haven’t used Django for a long time but when I did I found it one of the best documented projects out there.
Maxion•about 2 hours ago
Django is boring, which is why it works well. Use the ORM together with DRF serializers and an OpenApi generator and you can create TS types and TS client directly from your API.

Works incredibly well almost straight out of the box for even quite large applications. Once you start to grow out of it, it's easy to bypass the ORM and write raw sql queries.

You also won't be re-writing your backend every few years, the cost of which techbros often ignore.

aitchnyu•about 1 hour ago
If the DRF stack seamless like Ninja now?
stavros•about 2 hours ago
I agree, Django is just fantastic. Nothing is perfect, but Django is just really well-designed, with components that fit together naturally into a balanced whole.
weatherlite•about 2 hours ago
Just wanted to say I saw your last stand up , you're hilarious!
ustad•5 minutes ago
Stavros Halkias! Very funny guy. And also a maker and HN god! Never would have thought.
DoctorDabadedoo•28 minutes ago
What a random way to find out a stand up comedian I see now and then share a craft!
stavros•about 2 hours ago
Thanks, my love of comedy is only surpassed by my love of Django.
weatherlite•about 2 hours ago
Naa you lie you love twinkies more than Django
cryo32•about 2 hours ago
My favourite part of Django is it's not Rails :)
0x4d4c•about 1 hour ago
Why is that? What's wrong with Rails?
panzerboy•about 1 hour ago
It's made by DHH.
Nextgrid•15 minutes ago
Some people are just looking to be offended. You don’t have to read or agree with his drivel to use his software.

(Do you also check out the blogs/social media of every dev involved in every library you use?)

BoumTAC•about 1 hour ago
The DHH hate is absolutely crazy on HN.

I don't understand how people can be so out of touch.

0x4d4c•about 1 hour ago
And great bunch of other, awesome people.

I can take an argument of not buying a Tesla in order to avoid supporting Elons financial empire, but not using Rails because DHH made it is really hard to comprehend.