Learn the complete concept of Django ORM thoroughly with querysets and relationships between fields and the problem solved by ORM & problem with Django ORM.

seen from Italy

seen from United Kingdom
seen from Yemen
seen from United States
seen from Türkiye
seen from United States

seen from Türkiye
seen from United States
seen from Germany
seen from Germany
seen from China

seen from Sweden
seen from Germany
seen from Sweden
seen from France
seen from China
seen from Sweden
seen from Germany

seen from Italy
seen from Italy
Learn the complete concept of Django ORM thoroughly with querysets and relationships between fields and the problem solved by ORM & problem with Django ORM.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Django'da tehlikeli template etiketi: length.
Bugün yeni projeyle uğraşırken template içinde bir noktanın baya yavaş render edildiğini hissettim. (Bu arada Markafoni'den ayrıldım onu bilhare anlatırım.) Template içerisinde bir QuerySet length template filtresiyle çağırılıyordu:
{% if BlaBla.all|length == 5 %} .. {% endif %}
length template filtresini açıp baktığımda verilen değeri len fonksiyonuna geçirdiğini gördüm:
@register.filter(is_safe=False) def length(value): """Returns the length of the value - useful for lists.""" try: return len(value) except (ValueError, TypeError): return 0
İşte tam da arıza burada başlıyor. Len fonksiyonu ile bir QuerySet'in uzunluğunu almaya çalıştığınızda QuerySet'in tamamını veritabanından alıp, bir listeye dönüştürüp ardından listenin uzunluğunu alıyor. Bu da devasa tablolarda hem memory sıkıntısı, hem de veritabanı sunucularını gereksiz meşgul etmek demek. Sqldebugshell ile len metodunun nasıl bir sorgu çalıştırdığına baktığımda manzara şu şekilde:
In [6]: len(BlaBla.objects.all()) SELECT `c..`.`id`, `c..`.`i..`, `c..`.`p..`, `c..`.`c..`, `c..`.`s..`, `c..`.`i..`, `c..`.`i..`, `c..`.`u..`, `c..`.`u..`, `c..`.`s..`, `c..`.`c..`, `channel_customstream`.`t..` FROM `channel_customstream`
Görüldüğü üzere o modele ait her şeyi toplayarak alan bir sorgu oluşturdu. Halbuki count metodu QuerySet'lerin direkt olarak veritabanında Count çalıştırması sağlanabiliyor:
In [5]: CustomStream.objects.count() SELECT COUNT(*) FROM `channel_customstream`
Diyeceğim o ki, length etiketini count sorgusu yaptığını sanarak kullanmayınız.
Queryset + Queryset
querysets = queryset1 | queryset2