... います: from django.contrib.syndication.views import Feed from django.urls import reverse from policebeat.models import NewsItem class LatestEntriesFeed ( Feed ): title = "Police beat site news" link = "/sitenews/" description = "Updates on changes an ... d additions to police beat central." def items ( self ): return NewsItem . objects . order_by ( "-pub_date" )[: 5 ] def item_title ( self , item ): return item . title ... def item_description ( self , item ): return item . description # item_link is only needed if NewsItem has no get_absolute_url meth ... ... 0 ) class Order ( models . Model ): reference = models . CharField ( max_length = 20 , primary_key = True ) class OrderLineItem ( models . Model ): pk = models . CompositePrimaryKey ( "product_id" , "order_id" ) product = models . ForeignKey ( Produc ... > product = Product . objects . create ( name = "apple" ) >>> order = Order . objects . create ( reference = "A755H" ) >>> item = OrderLineItem . objects . create ( product = product , order = order , quantity = 1 ) >>> item . pk (1, "A755H") pk 属性 ... に tuple を代入することで、対応するフィールドの値をまとめて設定できます: >>> item = OrderLineItem ( pk = ( 2 , "B142C" )) >>> item . pk (2, "B142C") >>> item . product_id 2 >>> item . order_id "B142C" 複合 ... ... してください: from django.contrib.gis.feeds import Feed class MyFeed ( Feed ): # First, as a class attribute. geometry = ... item_geometry = ... # Also a function with no arguments def geometry ( self ): ... def item_geometry ( self ): ... # And as a f ... unction with a single argument def geometry ( self , obj ): ... def item_geometry ( self , item ): ... geometry ( obj ) get_object() で返されたオブジェクトを受け取り、 feed のジオメトリを返します ... obj ): # Can also return: `obj.poly`, and `obj.poly.centroid`. return obj . poly . extent # tuple like: (X0, Y0, X1, Y1). item_geometry ( item ) これをセットすると、フィードの各 アイテム のジオメトリを返します。これは GEOSGeometry のインスタンス、 あ ... ... の作成を自動化します。 これは Django の 配信 (syndication) フレームワーク のように動作します。サイトマップを作成するには、 Sitemap クラスを書き、 URLconf の中でそれを指定します。 インストール サイトマップ アプリをインストールするには、以下の手順に従っ ... てください。 'django.contrib.sitemaps' を INSTALLED_APPS 設定に追加します。 TEMPLATES 設定には、 DjangoTemplates バックエンドが含まれており、 APP_DIRS オプシ ... 必要があるのは、 Loader() テンプレートローダーがデフォルトのテンプレートを見つけられるようにするためです)。 初期設定 views. sitemap ( request , sitemaps , section = None , template_name = 'sitemap.xml' , content_type = 'application/xml' ) Django サイト ... ... = "A group blog by the sharpest minds in online media/journalism/publishing." , ... language = "en" , ... ) >>> feed . add_item ( ... title = "Hello" , ... link = "https://www.holovaty.com/test/" , ... description = "Testing." , ... ) >>> with open ( ... であるべきです。 stylesheets には、文字列または Stylesheet インスタンスのいずれかのシーケンスを指定する必要があります。 add_item ( title , link , description , author_email = None , author_name = None , author_link = None , pubdate = None , comments = ... None , unique_id = None , categories = () , item_copyright = None , ttl = None , updateddate = None , enclosures = None , ** kwargs ) [ソース] フィードにアイテムを追加しま ... ... page contains no results >>> page2 . previous_page_number () 1 >>> page2 . start_index () # The 1-based index of the first item on this page 3 >>> page2 . end_index () # The 1-based index of the last item on this page 4 >>> p . page ( 0 ) Traceback ( ... ... 2" DATABASE_USER = "myusername" DATABASE_PASSWORD = "s3krit" These settings are now in a dictionary named DATABASES . Each item in the dictionary corresponds to a single database connection, with the name 'default' describing the default database con ... late attributes). You should ensure that you always specify title_template and description_template attributes, or provide item_title() and item_description() methods. However, LatestEntriesByCategory uses the get_object() method with the bits argume ... ... これは特に、何かを数えるときに顕著に現れます。 たとえば、次のようなモデルがあるとします: from django.db import models class Item ( models . Model ): name = models . CharField ( max_length = 10 ) data = models . IntegerField () それぞれの data 値が、並 ... べ替えられたクエリセットに何回現れるかを数えたい場合は、次のようにします: items = Item . objects . order_by ( "name" ) # Warning: not quite correct! items . values ( "data" ) . annotate ( Count ( "id" ... )) ...これは Item オブジェクトを共通の data 値でグループ化し、各グループの id 値の数をカウントします。ただし、これはうまくいきません。 name ... ... ) (backends.base.SessionBase のメソッド) __contains__() (backends.base.SessionBase のメソッド) (QueryDict のメソッド) __delitem__() (backends.base.SessionBase のメソッド) (HttpResponse のメソッド) __eq__() (Model のメソッド) __getattr__() (Area のメソ ... ッド) (Distance のメソッド) __getitem__() (backends.base.SessionBase のメソッド) (HttpResponse のメソッド) (OGRGeometry のメソッド) (QueryDict のメソッド) (Spat ... (HttpRequest のメソッド) (ModelChoiceIterator のメソッド) (OGRGeometry のメソッド) __len__() (OGRGeometry のメソッド) __setitem__() (backends.base.SessionBase のメソッド) (HttpResponse のメソッド) (QueryDict のメソッド) __str__() (Model のメソッド) ( ... ... い場合にも便利です。例えば data という辞書がある場合、以下のように辞書内のキーと値を表示できます: {% for key , value in data.items %} {{ key }} : {{ value }} {% endfor %} ドット演算子を使う場合、メソッドよりも辞書キーへの参照が優先することに注意してくだ ... さい。したがって、もしも data 辞書が 'items' という名前のキーを持っていたなら、 data.items は data.items() ではなく data['items'] の値を出力します。テンプレート内で辞 ... 書のメソッドを使いたい場合、そのような名前のキー ( items 、 values 、 keys など) を辞書に追加しないでください。ドット演算子による参照の優先順位についての詳細は テンプレート変数の ... 2026年10月08日