class Author(models.Model):
name = CharField()
class Book(models.Model):
title = CharField()
author = ForeignKey(Author)
{% for book in books %}
{{ book.author.name }} // допълнителна заявка
{% endfor %}
Book.objects.select_related('author').all()
Author.objects.prefetch_related('book_set').all()
books = Book.objects.all()
books.count() # бързо
len(books) # по-бавно
{{ books|length }} # още по-бавно
{% if books %}
Number of books: {{ books|length }}
{% for book in books %}
- {{ book.title }}
{% endfor %}
{% endif %}
class Book(models.Model):
title = CharField(db_index=True)
author = ForeignKey(Author)
Ускоряват четенето: filter(), exclude(), order_by()
class Book:
...
class Meta:
ordering = ['title']
Book.objects.all()
Book.objects.all().order_by() # премахва сортирането на QuerySet-a
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
{% load compress %}
{% compress css %}
{% endcompress %}
{% load compress %}
{% compress js %}
// Ще мине development
// ... най-вероятно и staging
// ... на production - 500 (при offline compression mode)
var someVariable = {{ some_variable|safe }};
{% endcompress %}
Both David Cramer and Graham Dumpleton asked why --thunder-lock is not the default when multiprocess + multithread is requested.
This is a good question with a simple answer: we are cowards who only care about money.
"DAMN ! worker 5 (pid: 9531) died :( trying respawn ..."