It's like 4 lines of code that saves you so much grief later on:
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
AUTH_USER_MODEL = "myapp.User"
If you never need it, those 3 lines are not hurting you. In terms of a default, I think it probably would be nicer if Django pushed you to do this up front.No, there are frameworks out there that doesn't allow queries during template rendering. See Lucky for an example, https://luckyframework.org/.
The solution of using eager loading has nothing to do with whether you run your query in the template or in code.
Anyone who claims that it's fine to run queries in templates has smoked something really good. Personally, I'll continue to aggregate all my data using JOINs before presenting them.
However due to how Django handles queries by default, calling the ORM won't actually execute the query until the queryset is evaluated in most cases (unless requesting a single object or doing an aggregation), so your queries are still technically "ran" from the template - even if you are doing prefetch_related.
I personally don't have a problem with that; explicitly casting the queryset to a list before rendering a template seems like unnecessary boilerplate and still doesn't actually isolate you from the "N+1" queries problem if your template then accesses an object's relation that hasn't been prefetched.
You'll never have to worry about whether {{ pizza.topping.name }} is hitting the database ever again, especially, if you install django-zen-queries because it will raise an exception if you try to.
for pizza in pizzas:
print(pizza.topping.name)
But you'll certainly do the following in templates: {% for pizza in pizzas %}
<p>{{ pizza.topping.name }}</p>
{% endfor %}
I also don't understand why you want to avoid 3rd party packages, especially if it helps you write better code.I'm not necessarily trying to avoid third-party packages, in fact I've installed the package you suggested in one of my projects and will be trying it out.
Furthermore, this:
> As you can see, Django doesn’t have your best interest at heart. Instead of providing sane defaults, it punishes you for not being a master at the framework.
Is just nonsense.
Regarding 1. While this is certainly an issue, it’s an issue for anyone using any framework and a challenge of database-backed web applications everywhere. It’s also heavily documented by Django and one of the first things mentioned. Lazy querysets are actually very useful when you need to build queries over a number of steps. Explicit query sets can have their own subtle issues with performance.
2. The default user model is fine for most users. It’s not a bad default and there is clear documentation on how to extend it. It’s designed to be extended!
3. I rarely rename migrations. Maybe this is a good idea, but it’s hardly a harmful default.
4. I almost never rename my tables. Again, maybe a sensible suggestion, not a harmful default.
5. Strangely this seems to be the most un-Django suggestion that would have the largest effect on a project but hardly any detail is given here. I never do this and wouldn’t recommend anyone else to when staring off.
6. I think project structure and CLI is one place where Django is weak but again this is hardly a harmful default. Use django-cookiecutter.
Anyway I feel like the author is trying to manufacturer controversy to help define their expertise (not to say they aren’t a good Django developer, I have no idea). Some of these are good suggestions and “top tips” but they’re certainly not instances of Django trying to harm you.