3 ms·
I've worked with SQL for a long time, with a variety of implementations and front-ends. Django's object model hurt my head. I didn't get it. There's simply t
by jjguy 18y ago
I've worked with SQL for a long time, with a variety of implementations and front-ends. Django's object model hurt my head. I didn't get it. There's simply too much black magic.
e.g, how is:
Entry.objects.filter(
headline__startswith='What').exclude(
pub_date__gte=datetime.now()).filter(
pub_date__gte=datetime(2005, 1, 1))
(from http://www.djangoproject.com/documentation/db-api/ http://www.djangoproject.com/documentation/db-api/)
easier than:
SELECT * from Entry where headline like "What%" and pub_date... wha? see? wtf is that chaining filter actually doing?
my 2 cents: write your own DB access layer, fight the obscure black magic.
(nothing but quibbles with the templating engine, though)
- mattdennewitz 18y agothe filter gives you a tangible "query" to work with so that you can continually add criteria as you build your query. for example, i can say: grants = Grants.objects.filter(is_approved=True) to get all of the Grants to an Organization, and then if not request.user.is_superuser: grants = grant.filter(sponsoring_trustee=request.user) to filter out grants that only pertain to a certain user. "grants" isnt evaluated (queried) until its iterated over or otherwise called (print, for example), so i can keep building what i want as i go without having several sql calls or managing building a query via string concatenation. personally, i've always found django's orm to feel natural.