4 ms·
My app is a Django backend and a Vue frontend. There are large swathes of Django that I ignore, but to me the core of Django — its ORM, routing and middleware s
by jmduke 3y ago
My app is a Django backend and a Vue frontend. There are large swathes of Django that I ignore, but to me the core of Django — its ORM, routing and middleware system, and admin interface — are worth their weight in gold. The migration from DRF to Django-Ninja (which is, roughly, FastAPI + Django) has also been a great improvement in terms of productivity and performance.
Not a lot of whizbang features in 5.0, but GeneratedField looks like a very nice addition, and reason enough to migrate.
- malux85 3y agoMine too - Vue and django, and the django rest framework, it’s super productive - no writing all the crud views manually for the hundreds of models I have, the django admin interface is very helpful like you say, and backend is running (a very highly customized) django celery mix, Django + REST framework takes a little more to learn than something like FastAPI, but once you understand how all the middleware, permission and query classes work, you can be hyper productive
- sprainedankles 3y agoAny resources/examples you'd recommend for a Vue frontend w/django? I've been pretty firmly in backend land for a while and would to experiment with the other half of the puzzle!
- jmduke 3y agoI'll preface all of this with a couple esoteric design goals that I had in mind: 1. I actually _want_ an SPA. You might not need an SPA, if you don't need one then Vue/React/etc are overkill, etc. 2. I want to power as much of the SPA as I can using the same REST API as my core product, both for dogfooding reasons and for consolidation. Many people might argue that this is a bad idea. --- With that in mind, some specific packages that I highly recommend: 1. Django-vite (https://github.com/MrBin99/django-vite https://github.com/MrBin99/django-vite). This makes it very easy to serve an SPA from the actual django response/request model 2. Some sort of way to get type information (if you're using TypeScript) into the frontend. I use a frankensteined system of the OpenAPI spec that django-ninja generates + openapi-typescript (https://github.com/drwpow/openapi-typescript https://github.com/drwpow/openapi-typescript). This means when I add, say, a new field to a response in Django, I immediately get typechecking for it in Vue — which has been _tremendously_ useful. 3. Django-typescript-routes (a package I extracted and open-sourced!: https://github.com/buttondown-email/django-typescript-routes https://github.com/buttondown-email/django-typescript-routes) which gives your front-end routing information based on the Django router.
- zelphirkalt 3y agoIf you really need VueJs in the frontend, consider, that you can simple serve the VueJs on any page where it is actually needed. VueJs does not necessarily mean you must create a SPA. VueJs can be delivered like any other script and this is often the easiest way without having to commit to build a full blown SPA.
- jim180 3y agoComing from iOS/macOS background, I've kinda enjoyed Django with its all time classics (forms, templates, etc.) + HTMX. Admin interface was extremely helpful, when we are trying to validate business idea.
- amir_karbasi 3y agoHow was the effort to migrate from DRF to Django-Ninja? I saw Django-Ninja mentioned in another post and am thinking of switching one of my projects over from DRF. After skimming their documentation, it looks very pleasant and simple and perfect for my use case.
- jmduke 3y agoGoing from 0 → 1 migrated route was "medium difficulty", I'd say — there was a non-trivial amount of scaffolding I had to build out around auth, error codes, and so on, and django-ninja's docs are still a little lackluster when it comes to edge cases. Once I had that one migrated route, though, the rest were very simple. (And I am very happy with the migration overall!)
- crucialfelix 3y agoI've had that on my list to try out for a while now. FastAPI is a joy, having generated OpenAPI is a must, so Ninja sounds good. I've had quite enough of DRF's tower of mixins and rails like magic. It always sucks up development time and fails too easily.
- collyw 3y agoAgreed, the admin makes development so much easier, being able to easily enter and view your data.
- cdcarter 3y agoGeneratedField looks interesting, but I'm not _really_ sure what gains I get over just calling annotate() on my queryset with some computed fields. At least on the backends where the computed GeneratedField isn't stored.
- radus 3y agoIt's easier to re-use if you need the same generated field in multiple places.
- cdcarter 3y agoI've been in the habit of replacing the default manager for my model with one with an annotated query set. that way, any Model.objects.all() call will have the computed fields. I find this pretty easy to get used to and re-use. though I do admit I like them defined as actual model-fields with verbose names etc...
- OJFord 3y agoIt's a generated column in the database, vs. annotate is just a python alias for something you're selecting in the query.
- tmnvix 3y agoActually having the derived data in the database would be helpful for simplifying something like a website search implementation. I know I could have used it last month!