As I’ve been working on a project at
Indieflix, I’ve been evaluating other people’s code, including drop-ins, and for the past couple of days a pattern has emerged that, at first, bugged the hell out of me. Django has these lovely things called context processors- they allow you to attach specific elements of code to the request context before the
(
Read more... )
Comments 2
my_query = \
models.Foo.objects.filter(field1=val1) \
.exclude(field2=val2, field3=val3) \
.extra(where='func(field4, %s) < 0 ( ... )
Reply
Django 1.2 seems to be much better at avoiding this kind of nonsense.
Also, I've discovered that if your querysets are lazy but even constructing is expensive, you can still avoid the construction costs when they're not needed by crafting a constructor into a functor or closure that doesn't get triggered until invoked by the template handler.
[Edit: Wow, that last paragraph is so buzzword-compliant, if I were hearing it from someone else I couldn't be sure if they were bullshitting me or not.]
Reply
Leave a comment