per page, with , order by , clip by
Results of 1 - 10 of about 137 for self (0.007 sec.)
配信 (syndication) フィード フレームワーク 11076
配信 (syndication) フィード フレームワーク Django には、 RSS と Atom フィードを作成するための高レベルな配信 (syndication) フィード生成フレームワークが付属しています。 任意の配信フィードを作成するには、短い Python クラスを書くだけで済みます。 ... e beat site news" link = "/sitenews/" description = "Updates on changes and 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 method. def item_link ( ... self , item ): return reverse ( "news-item" , args = [ item . pk ]) このフィードにURLを接続するには、 URLconf にFeedオブジェクト ...
https://man.mtool.work/django/6.1/ref/contrib/syndication.html
テストツール 10860
テストツール Django は、テストを書くのに便利なツールをいくつか提供しています。 There are community-maintained solutions! Django has a vibrant ecosystem. There are testing and fixtures solutions highlighted on the Community Ecosystem page. T ... とえば、次のようにレスポンスを提供するビューを検証するために func 属性を使えます。 # my_view here is a function based view. self . assertEqual ( response . resolver_match . func , my_view ) # Class-based views need to compare the view_class, as the # ... functions generated by as_view() won't be equal. self . assertIs ( response . resolver_match . func . view_class , MyView ) 指定された URL が見つからない場合、この属性にアクセス ... 数に格納される必要があります (新しい SessionStore は、この属性がアクセスされるたびに作られるためです): def test_something ( self ): session = self . client . session session [ "somekey" ] = "test" session . save () Client. asession () session 属性と同 ...
https://man.mtool.work/django/6.1/topics/testing/tools.html
クラスベースのビューでミックスイン (mixin) を使用する 9925
クラスベースのビューでミックスイン (mixin) を使用する 注意 This is an advanced topic. A working knowledge of Django's class-based views is advised before exploring these techniques. Django のビルトインのクラスベースビューではたくさんの機能が ... terestView ( SingleObjectMixin , View ): """Records the current user's interest in an author.""" model = Author def post ( self , request , * args , ** kwargs ): if not request . user . is_authenticated : return HttpResponseForbidden () # Look up the ... author we're interested in. self . object = self . get_object () # Actually record interest somehow here! return HttpResponseRedirect ( reverse ( "author-d ... etail" , kwargs = { "pk" : self . object . pk }) ) 実際には、リレーショナルデータベースではなく、キーバリューストアに関心事を記録したいと思うでしょう。その ...
https://man.mtool.work/django/6.1/topics/class-based-views/mixins.html
クラスベースのビューでフォームを扱う 9457
クラスベースのビューでフォームを扱う フォームの処理には、一般に3つの場合分けが存在します。 最初の GET リクエスト (空白またはデフォルト値が埋め込まれたフォームを返す) 無効なデータの POST リクエスト (よくあるパターンは、エラー表示を追加したフ ... m ( forms . Form ): name = forms . CharField () message = forms . CharField ( widget = forms . Textarea ) def send_email ( self ): # send email using the self.cleaned_data dictionary pass このとき、ビューは FormView を使うことで構築できます。 views.p ... ctFormView ( FormView ): template_name = "contact.html" form_class = ContactForm success_url = "/thanks/" def form_valid ( self , form ): # This method is called when valid form data has been POSTed. # It should return an HttpResponse. form . send_em ... urls import reverse class Author ( models . Model ): name = models . CharField ( max_length = 200 ) def get_absolute_url ( self ): return reverse ( "author-detail" , kwargs = { "pk" : self . pk }) そうしたら、 CreateView およびその仲間たちを使って実際 ...
https://man.mtool.work/django/6.1/topics/class-based-views/generic-editing.html
はじめての Django アプリ作成、その 5 8774
はじめての Django アプリ作成、その 5 このチュートリアルは チュートリアル 4 の続きです。Web 投票アプリケーションが完成したので、今度は自動テストを作ってみましょう。 困ったときは: このチュートリアルの実行に問題がある場合は、FAQ の Getting Hel ... from .models import Question class QuestionModelTests ( TestCase ): def test_was_published_recently_with_future_question ( self ): """ was_published_recently() returns False for questions whose pub_date is in the future. """ time = timezone . now () ... + datetime . timedelta ( days = 30 ) future_question = Question ( pub_date = time ) self . assertIs ( future_question . was_published_recently (), False ) ここでは、未来の日付の pub_date を持つ Question のインス ... all last ) : File "/path/to/djangotutorial/polls/tests.py" , line 16 , in test_was_published_recently_with_future_question self.assertIs ( future_question.was_published_recently () , False ) AssertionError: True is not False ------------------------- ...
https://man.mtool.work/django/6.1/intro/tutorial05.html
Django の admin サイト 8774
Django の admin サイト Django のパワフルな特徴の1つは、自動的に生成される admin インタフェースです。あなたのモデルクラスからメタデータを読み取り、モデル中心のインタフェースを提供します。このインタフェースのおかげで、ユーザはあなたのサイトの ... n ): pass このデコレータは、model admin クラスをその __init__() メソッド内で参照する必要がある場合(例: super(PersonAdmin, self).__init__(*args, **kwargs) )には使用できません。代わりに super().__init__(*args, **kwargs) のようにします。 admin ファイル ... ): list_display = [ "name" , "title" , "view_birth_date" ] @admin . display ( empty_value = "???" ) def view_birth_date ( self , obj ): return obj . birth_date ModelAdmin. exclude この属性を使用する場合、フォームから除外するフィールドの名称をリストで ... admin . ModelAdmin ): list_display = [ "upper_case_name" ] @admin . display ( description = "Name" ) def upper_case_name ( self , obj ): return f " { obj . first_name } { obj . last_name } " . upper () モデルの属性や (必須の引数を持たない) メソッドを ...
https://man.mtool.work/django/6.1/ref/contrib/admin/
独自のテンプレートタグとフィルタを作る 8391
独自のテンプレートタグとフィルタを作る Django のテンプレート言語は、アプリケーションのプレゼンテーションロジックのニーズに対応するように設計された、多種多様な 埋め込みタグやフィルタ を搭載しています。それでもなお、テンプレート構成要素のコア ... 義する必要があります: import datetime from django import template class CurrentTimeNode ( template . Node ): def __init__ ( self , format_string ): self . format_string = format_string def render ( self , context ): return datetime . datetime . now () ... . strftime ( self . format_string ) メモ: __init__() は do_current_time() から format_string を取得します。オプションやパラメータ、引数は常に ... ドはこの目的で使用できる autoescape というパラメータを受け取ります。例えば: from django.template import Context def render ( self , context ): # ... new_context = Context ({ "var" : obj }, autoescape = context . autoescape ) # ... Do something with new ...
https://man.mtool.work/django/6.1/howto/custom-template-tags.html
複数のデータベース 8391
複数のデータベース ここでは、Djangoがサポートする複数データベースの扱いについて説明します。残りのDjangoのドキュメントの大部分は、あなたが一つのデータベース扱うことを前提としています。複数のデータベースを使いたいなら、いくつかの追加ステップを ... on models in the auth and contenttypes applications. """ route_app_labels = { "auth" , "contenttypes" } def db_for_read ( self , model , ** hints ): """ Attempts to read auth and contenttypes models go to auth_db. """ if model . _meta . app_label in ... self . route_app_labels : return "auth_db" return None def db_for_write ( self , model , ** hints ): """ Attempts to write auth ... and contenttypes models go to auth_db. """ if model . _meta . app_label in self . route_app_labels : return "auth_db" return None def allow_relation ( self , obj1 , obj2 , ** hints ): """ Allow relation ...
https://man.mtool.work/django/6.1/topics/db/multi-db.html
カスタムのモデルフィールドを作成する 8307
カスタムのモデルフィールドを作成する はじめに モデルリファレンス ドキュメントでは、Djangoの標準フィールドクラスである、 CharField や、 DateField などの使い方を説明しています。多くの場合、これらのクラスがあれば十分です。ただし、Djangoのバージ ... t , south and west . Our class looks something like this: class Hand : """A hand of cards (bridge style)""" def __init__ ( self , north , east , south , west ): # Input parameters are lists of cards ('Ah', '9s', etc.) self . north = north self . east ... = east self . south = south self . west = west # ... (other possibly useful methods omitted) ... これはDjangoの仕様を使っていない、普通 ... django.db import models class HandField ( models . Field ): description = "A hand of cards (bridge style)" def __init__ ( self , * args , ** kwargs ): kwargs [ "max_length" ] = 104 super () . __init__ ( * args , ** kwargs ) 私たちの HandField は、ほ ...
https://man.mtool.work/django/6.1/howto/custom-model-fields.html
マネージャ 8259
マネージャ class Manager [ソース] マネージャ (Manager) とは、Django のモデルに対するデータベースクエリの操作を提供するインターフェイスです。Django アプリケーション内の1つのモデルに対して、 Manager は最低でも1つは存在します。 Manager クラスの ... db import models from django.db.models.functions import Coalesce class PollManager ( models . Manager ): def with_counts ( self ): return self . annotate ( num_responses = Coalesce ( models . Count ( "response" ), 0 )) class OpinionPoll ( models . Mo ... どんなオブジェクトを返しても構いません。 QuerySet である必要はありません。 注目すべきもう1つの点は、 Manager 内のメソッドではself.modelとすることで、 Manager に紐づいているモデルクラスを取得できることです。 マネージャが初めに返す QuerySet を修正する Ma ... hlの本のみを返します: # First, define the Manager subclass. class DahlBookManager ( models . Manager ): def get_queryset ( self ): return super () . get_queryset () . filter ( author = "Roald Dahl" ) # Then hook it into the Book model explicitly. cla ...
https://man.mtool.work/django/6.1/topics/db/managers.html
PREV 1 2 3 4 5 6 7 8 9 10 NEXT