Live data from Hacker News

Django 1.11 beta 1 released

djangoproject.com

41–50 of 87 posts

Re: Django 1.11 beta 1 released

#41

Earlier quoted context omitted.

> The way I define queries by using a custom language in the form of keyword arguments makes me wonder why I don't just learn SQL instead? You have to learn SQL to use the Django ORM anyways; it's required knowledge in order to be able to wield the higher level abstraction effectively. However, the way you write a lot of these things in SQL is substantially more verbose and harder to compose.

>"However, the way you write a lot of these things in SQL is substantially more verbose and harder to compose." Could you give an example of something that's hard to compose with SQL? I'm sure ORMs have their advantages, I just want to understand how much benefit I could get from using one.

Queries across joins are the simple example. The ORM takes care of the join bit for you so you can write:

    Book.objects.filter(author__address__country='GB')
Rather than having to manage the joins with the author and address tables yourself.

Re: Django 1.11 beta 1 released

#42
post #2

Subquery expressions looks like it would be just easier to write SQL, instead of going through the Django ORM. This is where SQL starts to show its expressive strength over ORMs.

Absolutely. The amount of "magic" Django does slowly became a real detractor for me. The way I define queries by using a custom language in the form of keyword arguments makes me wonder why I don't just learn SQL instead? I would much rather do something like: models.Foo.objects.filter(sql=my_sql_query_str) Instead of something like: models.Foo.objects.filter(name='bar', parent__siblings__count__lt=3) And no special…

Try giving pyramid + sqlalchemy a shot. Way less magic, everything feels very pythonic and its a very mature stack that can scale really well.

Re: Django 1.11 beta 1 released

#43
post #18

This is a bit off topic, but can anyone suggest a decent Django tutorial? I've just recently learned python, and would like to build a few projects using Django. I completed Django's official tutorial[1], but when it came time for me to actually start building something, I found I didn't really understand what was going on. I should mention I'm inexperienced in both web application development and python in general.…

I haven't followed this one myself, but the django girls tutorial is supposed to be excellent. https://tutorial.djangogirls.org/en/

can confirm this tutorial is good, covers setting up virtual env for python / easy to follow

Re: Django 1.11 beta 1 released

#44
post #18

This is a bit off topic, but can anyone suggest a decent Django tutorial? I've just recently learned python, and would like to build a few projects using Django. I completed Django's official tutorial[1], but when it came time for me to actually start building something, I found I didn't really understand what was going on. I should mention I'm inexperienced in both web application development and python in general.…

I haven't followed this one myself, but the django girls tutorial is supposed to be excellent. https://tutorial.djangogirls.org/en/

I prefer djangogirls to two scoops - twoscoops is the way to go once you have learn the basics. But I felt it lacked a walkthru example

Re: Django 1.11 beta 1 released

#46
post #2

Subquery expressions looks like it would be just easier to write SQL, instead of going through the Django ORM. This is where SQL starts to show its expressive strength over ORMs.

Absolutely. The amount of "magic" Django does slowly became a real detractor for me. The way I define queries by using a custom language in the form of keyword arguments makes me wonder why I don't just learn SQL instead? I would much rather do something like: models.Foo.objects.filter(sql=my_sql_query_str) Instead of something like: models.Foo.objects.filter(name='bar', parent__siblings__count__lt=3) And no special…

You may be interested in the `.extra(...)` call on a QuerySet in Django. It allows you to specify hand-written SQL for various clauses, including `WHERE`.

https://docs.djangoproject.com/en/1.10/ref/models/querysets/...

Re: Django 1.11 beta 1 released

#47
post #2

Subquery expressions looks like it would be just easier to write SQL, instead of going through the Django ORM. This is where SQL starts to show its expressive strength over ORMs.

I learnt SQL before learning any ORM but the Django ORM just 'fits my brain' better. Especially when you factor in the fact that it handles 90% of common cases with a very simple syntax. In fact - due to lazy evaluation you can combine simple ORM queries and quite often you end up with subqueries behind the scenes. The Aggregate/Annotate syntax is a wonderful thing and I often find myself surprised writing queries that have some of that "Just Do What I Mean" magic.

Admittedly I rarely have to deal with the need for highly performant database code. But one could argue that performance problems are often better handled via caching or denormalisation (which really boil down to the same thing) than by clever work on the db side.

Re: Django 1.11 beta 1 released

#48

Earlier quoted context omitted.

> The way I define queries by using a custom language in the form of keyword arguments makes me wonder why I don't just learn SQL instead? You have to learn SQL to use the Django ORM anyways; it's required knowledge in order to be able to wield the higher level abstraction effectively. However, the way you write a lot of these things in SQL is substantially more verbose and harder to compose.

>"However, the way you write a lot of these things in SQL is substantially more verbose and harder to compose." Could you give an example of something that's hard to compose with SQL? I'm sure ORMs have their advantages, I just want to understand how much benefit I could get from using one.

    Post.objects.prefetch_related('author__company')
Often I want to avoid joins on big tables but still need to prefetch related fields on the objects I'm fetching. Example above fetches all the authors for the returned post, and then fetches all their companies. That's two additional fetches I don't have to write.

Re: Django 1.11 beta 1 released

#49
post #18

This is a bit off topic, but can anyone suggest a decent Django tutorial? I've just recently learned python, and would like to build a few projects using Django. I completed Django's official tutorial[1], but when it came time for me to actually start building something, I found I didn't really understand what was going on. I should mention I'm inexperienced in both web application development and python in general.…

I've been learning Django and found that most tutorials are out of date and very few go into detail. Two scoops even breezed over some aspects of the new project environment decisions they recommend (and share on Github). I've turned to asking for help from experts and on occasion hiring a mentor on sites like code mentor to answer questions for me.

Beats the cost of a coding academy and has let me go at my own pace.

Re: Django 1.11 beta 1 released

#50
post #3

Release notes with the new features in 1.11: https://docs.djangoproject.com/en/dev/releases/1.11/ Highlights: - better support for creating indexes on your Models with class-based indexes - widget rendering in forms now uses the templating system instead of python - Explicit subquery expression support via Subquery and Exists expressions.

widget rendering in forms now uses the templating system instead of python I haven't looked at how it's implemented yet, but that sounds like a real godsend.

They did the same with the login views, they are now class-based and easy to customize.

Very useful when you have an exotic templating engine for example and can't inherit the `registration/login.html` template

Post reply on HN