The Qiita Advent Calendar 2017 is supported by the following companies, organizations, and services.
The Qiita Advent Calendar 2017 is supported by the following companies, organizations, and services.
Django ORM の QuerySet には、select_related および prefetch_related というメソッドがありますが、イマイチ使い勝手がよく分からなかったりします。 公式ドキュメントにはこう書いてありますが、 select_related works by creating an SQL join and including the fields of the related object in the SELECT statement. For this reason, select_related gets the related objects in the same database query. However, to avoid the much larger result set that would result from joining a
djangoでヘテロなリストのprefetch djangoでヘテロなリストのprefetch。できないと思ったら普通に出来たのでわりとびっくりしたので記事にしてみた。 ヘテロなリスト? ここでのヘテロなリストと言うのは以下のようなリストを指している。 xs = [A(), B(), A(), A(), B(), C()] つまるところ1つの型のオブジェクトのリストではなく複数の型が混在したリストのようなものを指している。このようなリストは複数のことなるアイテムを要素として持つタイムラインのようなページを作ろうとした時に必要になる。例えば、このようなものをgeneric foreignkeyを使って以下の様に実装するということがあるかもしれない。 from django.contrib.contenttypes.fields import GenericForeignKey from dj
djangoでの集計は辛いという話 -- ORMは用法・用量を守って正しく使いましょう djangoのORMの機能の不足にぶち当たり辛いという話。別の言い方をすると、ORMは用法・容量守って正しく使いましょうという感じになるかもしれない。 はじめに 以下のような情報を年齢で丸めた値で集計してヒストグラムのようなものを作りたい。 名前 年齢 foo 10 bar 15 boo 20 結果 rank c 1 2 2 1 SQLでは頑張ればどうにかなる 集計をしたい時など何らかの演算の結果で GROUP BY したい時など結構ある。おそらくきっとある。 例えばヒストグラム的なものを作成したい時など。SQLであれば CASEとWHENを書き連ねることを気にしなければどうにかなる。 sqlite> create table person(name string primary key, age in
You cannot create m2m relations from unsaved objects. If you have the pks, try this: sample_object = Sample() sample_object.save() sample_object.users.add(1,2) Update: After reading the saverio's answer, I decided to investigate the issue a bit more in depth. Here are my findings. This was my original suggestion. It works, but isn't optimal. (Note: I'm using Bars and a Foo instead of Users and a S
こんばんは、Python界のひきこもりです。 モバイルアプリケーションのバックエンド開発などでRESTful APIを先ず設計する必要があるといったケースなんかで便利に利用できそうな、既存のウェブアプリケーションフレームワークの仕組みからRESTfulなAPI構成に特化してパッケージングされたサブフレームワークがいろいろ出てきているので調べました。 フレームワークに必要な機能そもそもフレームワークにどんな機能が必要なのかというのをChoosing an API framework for Django から抜粋。 ページネーション(アイテムの先頭から10件が1ページ目→11から20が2ページ目など) データの投稿とバリデーション メタデータの生成(result, count, next みたいな要素をレスポンスに含める為のしくみのことかな?) レスポンスのハンドリング キャッシュ データの
2012/09/24 Pythonコミュニティが開催する「PyCon JP 2012」が、東京の産業技術大学院大学で2012年9月15日から17日まで開催された。PyCon JPは世界中で行われてるPython Conference(PyCon)の日本版で、今回は2回目。「つながるPython」のテーマのもと初の併設イベントも開催され、東京開催にも関わらずヨーロッパ、オーストラリア、台湾など各国のPythonistaが集うなど、前年のほぼ倍の480人を超える参加者が集まり盛り上がった(レポート:タイムインターメディア・飯野卓見) PyCon JP本編ではPython製サービスの事例として写真共有サービス「SnapDish」やNIFTY Cloudに新しく加わったPaaSの「C4SA」のアーキテクチャ紹介、Pythonの非同期IOフレームワーク、「Gevent」と「Tornado」の発表、P
Home Home Tutorial API Guide Topics Community Django REST Framework Django REST framework is a powerful and flexible toolkit for building Web APIs. Some reasons you might want to use REST framework: The Web browsable API is a huge usability win for your developers. Authentication policies including packages for OAuth1a and OAuth2. Serialization that supports both ORM and non-ORM data sources. Cust
きのうの深夜に急に思い立ったので色々書いていきます!最近 Django の日本語情報少なすぎると思んで、ちょっとしたことでもこれからブログいっぱい書いていきます。— Yoichi Fujimoto (@wozozo) February 5, 2012 Django 1.3 から Class-based views が入って mixin とかしまくりでめんどくさくなったなーと思ってます。でも使えると便利なことも多いので、とりあえず JSON を返す view を書いてみましょうー。JSONResponseMixin はドキュメントからのコピペです。 https://docs.djangoproject.com/en/1.3/topics/class-based-views/#more-than-just-html from django import http from django.u
Backbone.js and other client-side MV* frameworks are a relatively new paradigm in designing and building rich web applications. Since this transition is still ongoing, most serious server-side frameworks are just now catching up to this trend. Django included. This is not a critique on Django - most sites and apps are still built in the "traditional" way. Backbone and friends are not a one-size-fi
Cross Site Request Forgery protection¶ The CSRF middleware and template tag provides easy-to-use protection against Cross Site Request Forgeries. This type of attack occurs when a malicious website contains a link, a form button or some JavaScript that is intended to perform some action on your website, using the credentials of a logged-in user who visits the malicious site in their browser. A rel
Django et compagnie Japonais. Djangoと日本の仲間たちDjango を体験しよう The Web framework for perfectionists with deadlines - www.djangoproject.com Django は Python で書かれたオープンソースのWebフレームワーク。見通しのよい MVC 分離、洗練された O/R マッピング API、そして汎用性の高い強力なテンプレートエンジンを備え、高い柔軟性とパフォーマンスを同時に要求されるWebアプリケーション開発をサポートします。 オブジェクト管理インタフェースやユーザ認証、セッション、国際化といった Webフレームワークとしての基本はもちろん、汎用のビューロジックや配信フィード (RSS/Atom) の生成など、Webアプリケーション開発に共通するメカニ
GeoDjango Tutorial¶ Introduction¶ GeoDjango is an included contrib module for Django that turns it into a world-class geographic web framework. GeoDjango strives to make it as simple as possible to create geographic web applications, like location-based services. Its features include: Django model fields for OGC geometries and raster data. Extensions to Django’s ORM for querying and manipulating s
昨日のPinterestの記事「Pinterestの急成長を支えてきたアーキテクチャとは? Pythonで開発しAmazonクラウドで運用」に続いて、やはり写真を中心としたサービスで急成長してきたInstagramのスケーラビリティについて、まとめてみました。 InstagramもPinterestと同様に、基本はAmazonクラウド上でPythonとフレームワークのDjangoを使ったシステムを構築しています。興味深いのは、創業者の二人ともバックエンドの経験がないなかで試行錯誤をしてシステムをスケールさせてきた点です。 Instagramは先月、Facebookに買収されると発表されています。この先、Instagramのシステムはどう変わっていくのでしょうか。 Instagramのシステム構成 約半年前、昨年12月にInstagramのブログに投稿された記事「What Powers In
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く