... m django.db import models class Reporter ( models . Model ): first_name = models . CharField ( max_length = 30 ) last_name = models . CharField ( max_length = 30 ) ... } " class Article ( models . Model ): headline = models . CharField ( max_length = 100 ) pub_date = models . DateField () reporter = models . ForeignKey ( Reporter , on_delete = models . CASCADE ) def __str__ ( self ): return self . headline class Meta ... : ordering = [ "headline" ] 以下は、Python API の機能を使って実行できる操作の例です。 複数の Reporter を作成する: >>> r = Reporter ( first_name = "John" , last_name = "Smith" , email = "john@example.com" ) >>> r . save () >> ... ... ベーススキーマの問題を解決してきた実績があります。 簡単な例を示しましょう: news/models.py from django.db import models class Reporter ( models . Model ): full_name = models . CharField ( max_length = 70 ) def __str__ ( self ): return self . full_name class ... del ): pub_date = models . DateField () headline = models . CharField ( max_length = 200 ) content = models . TextField () reporter = models . ForeignKey ( Reporter , on_delete = models . CASCADE ) def __str__ ( self ): return self . headline モデルのイン ... 、コードを作成する必要はありません: # Import the models we created from our "news" app >>> from news.models import Article , Reporter # No reporters are in the system yet. >>> Reporter . objects . all () <QuerySet []> # Create a new Reporter. >>> r = Repor ... ... レベルで必要な操作を記述する SQL 式を生成します。 例でやってみましょう。通常はこのようにします: # Tintin filed a news story! reporter = Reporters . objects . get ( name = "Tintin" ) reporter . stories_filed += 1 reporter . save () ここでは、 reporter.stori ... そのオブジェクトをデータベースに保存しています。しかし、代わりに次のようにすることもできます: from django.db.models import F reporter = Reporters . objects . get ( name = "Tintin" ) reporter . stories_filed = F ( "stories_filed" ) + 1 reporter . save () re ... Djangoが F() インスタンスを見つけると、標準のPython演算子をオーバーライドしてカプセル化されたSQL式を作成します。この場合、 reporter.stories_filed によって表されるデータベースフィールドをインクリメントするようにデータベースに指示する式が作成されます。 rep ... ... アノテートするだけです。実際のフィルタリングは Django のデフォルトのエラーレポートフィルタ ( django.views.debug.SafeExceptionReporterFilter ) で行われます。このフィルタはデコレータのアノテーションを使い、エラーレポートが生成される際に、対応する値をアスタリ ... 。このデフォルトの動作を上書きしたり、サイト全体でカスタマイズしたい場合は、独自のフィルタクラスを定義し、 DEFAULT_EXCEPTION_REPORTER_FILTER 設定でそれを使うように Django に指示する必要があります: DEFAULT_EXCEPTION_REPORTER_FILTER = "path.to.your.CustomExc ... eptionReporterFilter" また、 HttpRequest の exception_reporter_filter 属性を指定することで、任意のビューで使用するフィルタをより細かく制御 ... ... るもの に加えて、1つのログハンドラを提供しています。 class AdminEmailHandler ( include_html = False , email_backend = None , reporter_class = None , using = None ) [ソース] このハンドラは、受け取ったログメッセージごとにサイトの ADMINS に電子メールを送信しま ... idden. email_backend is not supported when MAILERS is defined or when the using argument is provided. AdminEmailHandler の reporter_class 引数では、メール本文で送信されるトレースバックテキストをカスタマイズするために django.views.debug.ExceptionReporter ... dlers" : { "mail_admins" : { "level" : "ERROR" , "class" : "django.utils.log.AdminEmailHandler" , "include_html" : True , "reporter_class" : "somepackage.error_reporter.CustomErrorReporter" , }, } Changed in Django 6.1: using 引数が追加されました。 バージ ... ... e-detail" ), ] 例 myapp/article_detail.html : < h1 > {{ object.headline }} </ h1 > < p > {{ object.content }} </ p > < p > Reporter: {{ object.reporter }} </ p > < p > Published: {{ object.pub_date | date }} </ p > < p > Date: {{ now | date }} </ p > cla ... ... FILE_PATH setting, used by the file email backend , now supports pathlib.Path . エラー報告 django.views.debug.SafeExceptionReporterFilter now filters sensitive values from request.META in exception reports. The new SafeExceptionReporterFilter.cleansed_su ... bstitute and SafeExceptionReporterFilter.hidden_settings attributes allow customization of sensitive settings and request.META filtering in exception reports ... . The technical 404 debug view now respects DEFAULT_EXCEPTION_REPORTER_FILTER when applying settings filtering. The new DEFAULT_EXCEPTION_REPORTER allows providing a django.views.debug.Exceptio ... ... lass ArticleForm ( ModelForm ): ... class Meta : ... model = Article ... fields = [ "pub_date" , "headline" , "content" , "reporter" ] ... # Creating a form to add an article. >>> form = ArticleForm () # Creating a form to change an existing article. >>> ... rt Article class ArticleForm ( ModelForm ): class Meta : model = Article fields = [ "pub_date" , "headline" , "content" , "reporter" , "slug" ] field_classes = { "slug" : MySlugFormField , } もしくは: from django.forms import ModelForm from myapp.models ... * kwargs ) class ArticleForm ( ModelForm ): class Meta : model = Article fields = [ "pub_date" , "headline" , "content" , "reporter" , "slug" ] formfield_callback = formfield_for_dbfield 最後に、フィールドを完全に -- タイプ、バリデータ、必須かどうかなどを ... ... a big responsibility, though. You have to be sure that the issue is really resolved, and you need to keep in mind that the reporter of the ticket may not be happy to have their ticket closed (unless it's fixed!). If you're not certain about closing a tic ... he request isn't appropriate for consideration in Django. Sometimes a ticket is closed as "wontfix" with a request for the reporter to start a discussion on the Django Forum if they feel differently from the rationale provided by the person who closed th ... ... ことで、それまでにミドルウェアで行われた変更を取り消し、元の ROOT_URLCONF を使用するようにできます。 HttpRequest. exception_reporter_filter これは、現在のリクエストに対して DEFAULT_EXCEPTION_REPORTER_FILTER の代わりに使用されます。詳細については、 カスタム ... エラーレポート を参照してください。 HttpRequest. exception_reporter_class これは、現在のリクエストに対して DEFAULT_EXCEPTION_REPORTER の代わりに使用されます。詳細については カスタムエラーレポ ... 2026年10月08日