Last active
June 1, 2018 02:19
-
-
Save kurianbenoy/ca9a0c0e29014091aa42352e5fa07fbe to your computer and use it in GitHub Desktop.
Difference between Django 2.0 and django 1.11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Django 2.0 | |
from django.urls import path | |
from . import views | |
urlpatterns = [ | |
path('articles/2003/', views.special_case_2003), | |
path('articles/<int:year>/', views.year_archive), | |
path('articles/<int:year>/<int:month>/', views.month_archive), | |
path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail), | |
] | |
# Django 1.11 | |
urlpatterns = [ | |
url(r'^articles/2003/$', views.special_case_2003), | |
url(r'^articles/([0-9]{4})/$', views.year_archive), | |
url(r'^articles/([0-9]{4})/([0-9]{2})/$', views.month_archive), | |
url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', views.article_detail), | |
] | |
Regarding Database features | |
There are now new feautures like : | |
1) Aggregation with Filter | |
django 2 | |
from django.contrib.auth.models import User | |
from django.db.models import Count, F | |
User.objects.aggregate( | |
total_users=Count('id'), | |
total_active_users=Count('id', filter=F('is_active')), | |
) | |
django 1.11 | |
from django.contrib.auth.models import User | |
from django.db.models import ( | |
Count, | |
Sum, | |
Case, | |
When, | |
Value, | |
IntegerField, | |
) | |
User.objects.aggregate( | |
total_users=Count('id'), | |
total_active_users=Sum(Case( | |
When(is_active=True, then=Value(1)), | |
default=Value(0), | |
output_field=IntegerField(), | |
)), | |
) | |
And lot more DBMS features like , you refer here : | |
https://docs.djangoproject.com/en/2.0/ref/models/querysets/ | |
Then there are new features to calculate rank like Windows function : | |
https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#window-functions | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment