... トを表示する例から見てみましょう。 ここでは、以下のようなモデルを使用します。 # models.py from django.db import models class Publisher ( models . Model ): name = models . CharField ( max_length = 30 ) address = models . CharField ( max_length = 50 ) city = ... s Book ( models . Model ): title = models . CharField ( max_length = 100 ) authors = models . ManyToManyField ( "Author" ) publisher = models . ForeignKey ( Publisher , on_delete = models . CASCADE ) publication_date = models . DateField () 次に、ビューを ... 定義しましょう。 # views.py from django.views.generic import ListView from books.models import Publisher class PublisherListView ( ListView ): model = Publisher 最後に、このビューを URL にフックさせます。 # urls.py from django. ... ... トを表示する例から見てみましょう。 ここでは、以下のようなモデルを使用します。 # models.py from django.db import models class Publisher ( models . Model ): name = models . CharField ( max_length = 30 ) address = models . CharField ( max_length = 50 ) city = ... s Book ( models . Model ): title = models . CharField ( max_length = 100 ) authors = models . ManyToManyField ( "Author" ) publisher = models . ForeignKey ( Publisher , on_delete = models . CASCADE ) publication_date = models . DateField () 次に、ビューを ... 定義しましょう。 # views.py from django.views.generic import ListView from books.models import Publisher class PublisherListView ( ListView ): model = Publisher 最後に、このビューを URL にフックさせます。 # urls.py from django. ... ... odels class Author ( models . Model ): name = models . CharField ( max_length = 100 ) age = models . IntegerField () class Publisher ( models . Model ): name = models . CharField ( max_length = 300 ) class Book ( models . Model ): name = models . CharFiel ... eld ( max_digits = 10 , decimal_places = 2 ) rating = models . FloatField () authors = models . ManyToManyField ( Author ) publisher = models . ForeignKey ( Publisher , on_delete = models . CASCADE ) pubdate = models . DateField () class Store ( models . ... な集計クエリは以下のようになります: # Total number of books. >>> Book . objects . count () 2452 # Total number of books with publisher=BaloneyPress >>> Book . objects . filter ( publisher__name = "BaloneyPress" ) . count () 73 # Average price across all boo ... ... odels class Author ( models . Model ): name = models . CharField ( max_length = 100 ) age = models . IntegerField () class Publisher ( models . Model ): name = models . CharField ( max_length = 300 ) class Book ( models . Model ): name = models . CharFiel ... eld ( max_digits = 10 , decimal_places = 2 ) rating = models . FloatField () authors = models . ManyToManyField ( Author ) publisher = models . ForeignKey ( Publisher , on_delete = models . CASCADE ) pubdate = models . DateField () class Store ( models . ... な集計クエリは以下のようになります: # Total number of books. >>> Book . objects . count () 2452 # Total number of books with publisher=BaloneyPress >>> Book . objects . filter ( publisher__name = "BaloneyPress" ) . count () 73 # Average price across all boo ... ... には、2つの異なるクエリセットを用意する必要があります: ListView で使用するための Book の クエリセット リストアップしたい本の Publisher にアクセスできるので、 get_queryset() をオーバーライドして、 Publisher の 逆方向の外部キーマネージャ を使用します。 Publis ... her queryset for use in get_object() 正しい Publisher オブジェクトを取得するには、デフォルトの get_object() の実装に頼りましょう。ただし、明示的に queryset 引数を渡さなければな ... りません。なぜなら、デフォルトの get_object() の実装では get_queryset() を呼び出しますが、これは Publisher の代わりに Book オブジェクトを返すようにオーバーライドしているからです。 注釈 get_context_data() については慎重に考える必要 ... ... には、2つの異なるクエリセットを用意する必要があります: ListView で使用するための Book の クエリセット リストアップしたい本の Publisher にアクセスできるので、 get_queryset() をオーバーライドして、 Publisher の 逆方向の外部キーマネージャ を使用します。 Publis ... her queryset for use in get_object() 正しい Publisher オブジェクトを取得するには、デフォルトの get_object() の実装に頼りましょう。ただし、明示的に queryset 引数を渡さなければな ... りません。なぜなら、デフォルトの get_object() の実装では get_queryset() を呼び出しますが、これは Publisher の代わりに Book オブジェクトを返すようにオーバーライドしているからです。 注釈 get_context_data() については慎重に考える必要 ... ... 書いたら、任意の Admin インスタンスに登録できます: from django.contrib import admin from myapp.models import Author , Book , Publisher # Import our custom ModelAdmin and TabularInline from where they're defined. from myproject.admin import MultiDBModelAdmin ... ize the multi-db admin objects for use with specific models. class BookInline ( MultiDBTabularInline ): model = Book class PublisherAdmin ( MultiDBModelAdmin ): inlines = [ BookInline ] admin . site . register ( Author , MultiDBModelAdmin ) admin . site . ... register ( Publisher , PublisherAdmin ) othersite = admin . AdminSite ( "othersite" ) othersite . register ( Publisher , MultiDBModelAdmin ) こ ... ... 書いたら、任意の Admin インスタンスに登録できます: from django.contrib import admin from myapp.models import Author , Book , Publisher # Import our custom ModelAdmin and TabularInline from where they're defined. from myproject.admin import MultiDBModelAdmin ... ize the multi-db admin objects for use with specific models. class BookInline ( MultiDBTabularInline ): model = Book class PublisherAdmin ( MultiDBModelAdmin ): inlines = [ BookInline ] admin . site . register ( Author , MultiDBModelAdmin ) admin . site . ... register ( Publisher , PublisherAdmin ) othersite = admin . AdminSite ( "othersite" ) othersite . register ( Publisher , MultiDBModelAdmin ) こ ... ... rom the tutorial in two different locations so we can serve the same functionality to two different audiences (authors and publishers). URL の名前空間は 2 つの部分に分かれ、両方とも文字列で表されます: アプリケーションの名前空間 ¶ デプロイされているアプリケ ... ュートリアルで扱った polls アプリケーションの 2 つのインスタンスの例を考えてみましょう: 1 つは 'author-polls' 、もう 1 つは 'publisher-polls' と名付けられています。polls を作成して表示するときにインスタンス名前空間を考慮するように、そのアプリケーションを拡張 ... rt include , path urlpatterns = [ path ( "author-polls/" , include ( "polls.urls" , namespace = "author-polls" )), path ( "publisher-polls/" , include ( "polls.urls" , namespace = "publisher-polls" )), ] polls/urls.py ¶ from django.urls import path from . ... ... rom the tutorial in two different locations so we can serve the same functionality to two different audiences (authors and publishers). URL の名前空間は 2 つの部分に分かれ、両方とも文字列で表されます: アプリケーションの名前空間 ¶ デプロイされているアプリケ ... ュートリアルで扱った polls アプリケーションの 2 つのインスタンスの例を考えてみましょう: 1 つは 'author-polls' 、もう 1 つは 'publisher-polls' と名付けられています。polls を作成して表示するときにインスタンス名前空間を考慮するように、そのアプリケーションを拡張 ... rt include , path urlpatterns = [ path ( "author-polls/" , include ( "polls.urls" , namespace = "author-polls" )), path ( "publisher-polls/" , include ( "polls.urls" , namespace = "publisher-polls" )), ] polls/urls.py ¶ from django.urls import path from . ... 2026年10月08日