4 ms·
Please note these are my opinions. The efficiency you gain using Django on the admin side is lost with every other part of your app. 1. Active Record is super
by whalesalad 8y ago
Please note these are my opinions.
The efficiency you gain using Django on the admin side is lost with every other part of your app.
1. Active Record is superior to the Django ORM (which is still good). Being able to set scopes and do a lot of conveniences right on the model without needing to extend/override a manager is great. Being able to connect to an existing database for free is also great.
2. Controllers are great. The way they can be nested and composed is also powerful. Being able to mount a resource at any level in the hierarchy either alongside or beneath (or both!) is hugely powerful. I can state concerns at each level and 'forget about it' deeper. Eg, if my controller A needs to ensure a given user has access to that resource and all children, I can do that at level A and trust its handled so in the controller for level B or C (deeper layers) I am not worried about it.
2b. The syntactic sugar to add authentication/authorization/guards in controllers is incredible. `before_request :ensure_access`
3. Active Support is phenomenal.
4. You can build very elegant, flexible and powerful RESTful and RESTish API's REALLY quickly. And not just naive stuff that you can do with something like 10 lines of Flask ... but really foundational stuff that allows you to hit the ground running and then build on it layering in more security and functionality.
5. Polymorphic/STI power with Active Record. AR gives you so much more freedom to do polymorphism and bend your database to model your data as you see fit. With Django you are oftentimes stuck doing things their way. For instance if I want multiple classes to share a single database and get instantiated based on a 'type' field ... that is trivial in Rails and difficult with Django. Even moreso if you want to do relationships with those polymorphic objects.
6. Finally... the most important thing... it's sometimes difficult to model your domain/business inside of Django and by extension the Django admin tool. Let's say you have a friendship between two people. How do you create that in Django? You might have a many-to-many which means there is gonna be a join table somewhere. Do you ask your customer support folks to go into the FriendRelationship UI and 'create an object' connecting person_a to person_b and ensuring to choose the correct relationship type from the enum? Worse, you have too many users so you cant use a select field or search box without plugins and are left with two input boxes that expect a valid person ID to the FK. So now customer support needs a workflow for managing this data. I'd rather build my own "manage friends" page that will take me all of an hour and provide an experience modeled after the problem/task not the database.
Or let's say you have a more intricate transactional type of process where an object needs to be created with 3 or 4 child objects. The parent needs to be created first, then the children need to be created and linked to that parent. Sure, you can do this in the Django admin flow but at that point you might as well be writing `INSERT INTO...` queries. Again, I'd rather build my own tool. I will save SO much time building the API and the business logic for my program that I'll be afforded the time to build an administrative tool that is focused on tasks specific to my team/business not just a graphical representation of my SQL tables.
I could go on and on and on. I was a Django zealot for a long time and refused to drink the kool-aid. I bought into the hype from the community and trusted folks when they said "rails is magic, I don't like it" but that is a horribly naive approach and frankly I only hear it from less experienced engineers. When you get acclimated to Rails you realize there is no magic, it's all just straightforward code written by people who truly want to get things done. Perhaps I just align more with the Ruby way of thinking. Django folks tend to pride themselves on boilerplate and more complex interactions... like it's some kind of badge of honor.
- joelbluminator 8y agoAbout point (6), how is this handled in Rails? I mean, in Activeadmin etc or did you mean something else?
- busterarm 8y agoYou take advantage of what the database gives you already (via Active Record) and Friendship is its own model of which People are members. People have many Friends (People) through Friendships. Friendships have many People. You stick a check in the update controller for Friendship to destroy the object unless it has two members (or not to create without two) and additionally you add a "validates_numericality_of :friends, on: [:create, :destroy]" check on the model itself. When someone "friends" another user, you create a new Friendship with both users as members. It's automatically bidirectional (but you probably want to add some approval logic in here, which is still pretty easy). The manage friends page discussed is just a collection of all of the Friendships of which you are a member. You can use either update or destroy to remove you from membership, because now either will achieve the same thing.
- joelbluminator 8y agoOK, I wasn't aware of a many to many pain in Django. Good to know.
- busterarm 8y ago> Django folks tend to pride themselves on boilerplate and more complex interactions... like it's some kind of badge of honor It's funny hearing this because I was under the impression one of Django's core principles was to avoid boilerplate. Like you, I've worked a ton in Rails and Django, but I started with Rails and always find Django work to be a slog -- particularly when it comes to environment configuration and administration. And the documentation for when you need to muck around under the hood is really not great. And, invariably every Django application I've come across has tons of boilerplate.