Live data from Hacker News

Django 5.0

djangoproject.com

201–210 of 237 posts

Re: Django 5.0

#201

Earlier quoted context omitted.

Me too, I prefer the API. At the end of the day I’m delivering reliable and productive solutions for my clients, and they don’t care what the tech is. However the Django API, GraphQL with React front end stack I’ve inherited is an frustratingly flakey to use and a nightmare to develop :-/ It’s so bad I’m regretting all my life choices that led me to this point LOL

I’m curious to hear what are some of the most frustrating points developing with Django, React, and GraphQL.

same here, maybe we can improve things!

Re: Django 5.0

#202

Earlier quoted context omitted.

Wagtail is absolutely fantastic for content-heavy websites, like blogs, journals, catalogues, archives, venues (event schedules), also everything that deals with loosely-structured data. It's much less useful as a general purpose CRUD framework - it's too focused on "content", it wouldn't spark joy. Also it's been a few years since I've last used it, but the overwhelming dominance of deeply nested JSON fields makes o…

> it's too focused on "content". Isn't that a good thing for a Content Management System ? I am not sure I understand what you think could be done to either the admin (or wagtail) to make them "CRUD frameworks".

Maybe I'll expand a little bit on the context... Both "CMS" and "CRUD framework" were unfortunate choices of words, and don't quite represent the actual problem.

The Django Admin implements the MVVM pattern; you declare a "ModelAdmin" (aka a ViewModel) subclass, where you can say things like "display the fields in this order" or "run this function to validate that field", and never ever touch any SQL, ORM, HTML, etc until necessary. It is extremely powerful: every line of declarative code saves you hundreds of lines of writing the lower layers; every line you can't write declaratively, can be instead expressed by a mere dozen, using the built-in escape hatches. This pattern of getting "just one layer below" can continue for quite a while, until you suddenly run into an unexpected hard wall.

For example, there is no way to mix the ordering of "fieldsets" and "inlines" (the latter being the only meaningful way to support M:N relations). The community has gathered a couple hacky workarounds (like post-processing the generated template to re-order the sections), but to address the root of the issue would be to merge "fieldsets" and "inlines" into a single property that controls both. So I've embarked on that task, and started hacking on the admin, only to find some of the most gruesome spaghetti entangling the path - I suspect big chunks of that code were hastily thrown together in mid-late 2000s, and barely touched since.

This is a recurring problem - almost every single customer I've talked to is about 95% happy with using the Django admin, but these tiny things that require disproportionate effort keep ruining our day.

Wagtail is not a general solution to this problem; it solves some of the larger pain points (for example, by liberally using JSONFields, which as I've mentioned come with problems of their own), but actually makes editing larger amounts of more structured data a bit more awkward, since it doesn't even come with all of Django admin's (limited) flexibility, and mixing the two in a single project results in an unmitigated UX disaster.

I think I have a pretty good idea of what I'd like to replace Django admin with, unfortunately I've done extensive research and none of the existing alternatives are quite it - you always have to give something up, because the tool is too specialized, makes too many assumptions about your use case. However I think the core principles of Django admin hold very strongly; it's just that the implementation is lacking, and probably will never be addressed, as ease of upgrading will always continue to win (and kudos to Django for that - again, I've been through quite a few legacy projects).

I think there is space for a third-party admin replacement that adheres to this spirit, but breaks all backwards compatibility to clean up the architecture. It would require careful and conservative tech stack choices; I'd like it to survive the next 20 years and allow projects built today to enjoy the same easy path forward. I'd be more than happy to work on that, unfortunately I'm a little preoccupied bending the existing code to my will ;)

Re: Django 5.0

#203
post #46

Earlier quoted context omitted.

We are using Django "Legacy" Apps.I am puzzled by the "new" Single Page Applications (SPAs). They require extensive routing, authentication, and GraphQL integration, all of which are already handled by Django's ORM and views.Additionally, Django efficiently manages forms. The primary advantage I see in SPAs is enhanced reactivity, which certainly improves user experience. However, HTMX seems sufficient in this aspect…

Broadly, if you're happy with Django and haven't felt the need to transition to SPA, power to you. This is the case in some industries. It's generally not the case in b2c, though, and if you haven't felt the pain yet then you likely aren't in touch enough with your customers (or you haven't connected the dots). I don't need to sell you on the concept though I will address your comment in depth. In general, React (esp…

I’d also add that if you use Typescript with an OpenAPI client generator (https://github.com/ferdikoomen/openapi-typescript-codegen) it can immensely alleviate some of the biggest pain points of seperate backend and front-end. It always used to be a major pain in the ass with the amount of overhead an API change would incur - updating documentation, postman, constant communication between backend and front-end devs, etc. Now I just npm run generate, I see new API changes in my Git client and Typescript errors for code that needs updating.

Also, using a library like Tanstack Query or Rdtk Query can almost completely eliminate manual state management, and kinda makes the whole development experience feel almost like SSR.

Re: Django 5.0

#204

Earlier quoted context omitted.

The python team I joined grew their codebase from a thin data access layer into a full blown application. Staff was full of data guys and had no idea about application engineering, but lots of opinions. The client was another company who intended the product as heart of their digital transformation. Guess who had to refactor this mess and steer away from catastrophy. I’m haunted to this day.

That general story can happen with any tech stack. POC whipped together without good architecture. Having proven itself, usage increases until the application starts to burst at the seams. Program must be redesigned, avoiding performance gotchas. I still think Django + the ORM give you a lot of runway before performance should be a concern.

Idk. The python stack strikes as particularly troublesome if you don’t know exactly what you’re doing. There are no guardrails for less experienced devs that prevents you from making basic mistakes.

I also realized mid project that the default rest framework doesn’t support good api model generation from OpenApi or vice versa. And most devs didn’t understand why using untyped dicts everywhere was bad.

In all transparency, I am openly biased for static typing and have a background in java, c# and Swift.

So what we ended up with looked similar to a statically typed language but without the tooling or performance.

Re: Django 5.0

#205

Earlier quoted context omitted.

I'm not criticising ORMs, just how active record works.

Well it's trivial in ActiveRecord to avoid n+1s by preloading associations. As with any technology, if you use it wrong and inefficently then things will be incorrect and slow.

Here's an example I remember: if I want to update a field in a million records in my database, I can't just send the update command to the database to run. Instead, an ActiveRecord ORM will try and load all the records into the application, and for each record object make the change in memory, and then persist the record.

If I'm remembering correctly, that is a fundamentally poor approach. Instead of telling the database to do some work, the database is doing more work, and the application is doing work. One mitigation is to batch the work[0]. Another is to special-case updates[1], which bypasses all the ActiveRecord pre/post-save logic. In either case you aren't holding the tool wrong. The tool is wrong.

[0] https://apidock.com/rails/ActiveRecord/Batches/find_each - you'll note that the batches are "subject to race conditions" - i.e. each batch is its own transaction! And you're still loading the records into your application pointlessly. You're just limiting how many do it at once.

[1] https://docs.djangoproject.com/en/dev/topics/db/queries/#upd... - note:

> Be aware that the update() method is converted directly to an SQL statement. It is a bulk operation for direct updates. It doesn’t run any save() methods on your models, or emit the pre_save or post_save signals (which are a consequence of calling save()), or honor the auto_now field option. If you want to save every item in a QuerySet and make sure that the save() method is called on each instance, you don’t need any special function to handle that. Loop over them and call save()

Re: Django 5.0

#206
post #47

Congrats on the release to the Django community! If anyone is curious, I updated my Django / Docker starter app to use Django 5.0 at: https://github.com/nickjj/docker-django-example It pulls together gunicorn, Celery, Redis, Postgres, esbuild and Tailwind with Docker Compose. It's set up to run in both development and production.

where do you tend to run stuff in production? and if you were a startup - any preferences?

It depends.

I personally use DigitalOcean but now that Hetzner is starting to get US data centers that is looking like a good option too.

With no other context, if I were creating a startup today I'd likely go with DigitalOcean.

AWS is also another option, especially if you think you'll be using some of their services.

But for a typical web app + SQL database + cache + object storage set up DO works nicely, although I would still use S3 for object storage even though DO has it, I find S3 to be more dependable.

Re: Django 5.0

#207

Earlier quoted context omitted.

Yes, jQuery is often derided as outdated, but it worked quite well for a very long time, with minimal hassle for developers. In fact, I was working full-time on static Elixir/Phoenix pages with jQuery sprinkled on top as late as 2022… it felt a bit clunky but it worked as advertised and wasn’t frustrating in any significant way.

I still use JQuery because of all the syntactic sugar and shortcuts.

I mean, a whole sea of WordPress developers still use JQuery. It's still out there and thriving.

Re: Django 5.0

#209

A huge part of the work I did the past year (and still do sometimes, email in my profile) was helping people transition from a full legacy django app to a lightweight django backend with rest api and a react frontend. Django Ninja makes it especially pleasant. I think django should really embrace this in the future. Make it easier to drop the superfluous parts; forms, templates … I don’t know what that will look like…

I've gone the opposite way. Started converting views to rest framework viewsets and building React components on the front end. It just created more problems. Now the React stuff is considered legacy and we're using HTMX and the bare minimum of vanilla JS when necessary.

> Now the React stuff is considered legacy

There's no point announcing things are now "legacy". Legacy is what Microsoft invented to call products they just made a competitor for, and the psychology seems the same. If it doesn't fit your needs, great. But React is useful for lots of needs.

Re: Django 5.0

#210

Earlier quoted context omitted.

REST Framework is frankly... flawed. Full of good ideas, but in practice, it leads to development hell unless you're very rigorous with it. FastAPI is the gold standard, which in the Django works means Django-Ninja. If you've been building individual React components and integrating them without going the SPA route, then while there are some upsides to that, you are doing a lot of the effort but not getting most of t…

The lesson learnt is that React is an "all or nothing" type thing. You'll notice "SPA" isn't mentioned at all on the React website, but there's lots of mentions of building components. There are lots of comments around places like HN of people learning the same lesson as me. We never scoped replacing our entire UI with React and entire backend with JSON API because it seemed like there was a smooth upgrade path, but…

> because it seemed like there was a smooth upgrade path, but there isn't really

You can put a React component into a non-React web page and give it data to render from however you like. Isn't that the intended path?

Post reply on HN