... できます。 定数として定義されたアセット アセットを定義する最も簡単な方法は、定数とすることです。この方法を利用するには、内部 Media クラスに宣言します。内部クラスのプロパティで必要なものを定義します。 以下に例を示します。 from django import forms class C ... alendarWidget ( forms . TextInput ): class Media : css = { "all" : [ "pretty.css" ], } js = [ "animations.js" , "actions.js" ] このコードでは、 CalendarWidget を定義 ... ァイル pretty.css と JavaScript ファイル animations.js および actions.js を読み込めるようになります。 この静的定義は実行時に media というウィジェットプロパティに変換されます。 CalendarWidget インスタンスのアセットリストは、このプロパティから取得できます ... ... 可能オブジェクトとして定義することもできます。例えば def get_currencies (): return { i : i for i in settings . CURRENCIES } class Expense ( models . Model ): amount = models . DecimalField ( max_digits = 10 , decimal_places = 2 ) currency = models . Ch ... ルクラスの内部で選択肢を定義し、それぞれの値に適切に名前づけられた定数を定義するのがベストです: from django.db import models class Student ( models . Model ): FRESHMAN = "FR" SOPHOMORE = "SO" JUNIOR = "JR" SENIOR = "SR" GRADUATE = "GR" YEAR_IN_SCHOOL_CH ... がインポートされていればどこでも動作します)。 利用可能な選択肢を、組織化のために名前付きグループにまとめることもできます。 MEDIA_CHOICES = { "Audio" : { "vinyl" : "Vinyl" , "cd" : "CD" , }, "Video" : { "vhs" : "VHS Tape" , "dvd" : "DVD" , }, "unknown" ... ... ommunity Ecosystem page. The Django Packages Admin interface grid has even more options for you! ModelAdmin のオブジェクト class ModelAdmin [ソース] ModelAdmin クラスは、admin インターフェース内でモデルを表現する方法です。通常、アプリケーション内の ad ... min.py に記述されます。 ModelAdmin の例を見てみましょう: from django.contrib import admin from myapp.models import Author class AuthorAdmin ( admin . ModelAdmin ): pass admin . site . register ( Author , AuthorAdmin ) いつでも ModelAdmin オブジェクト ... ューを追加したり変更したりするために、CSS や JavaScript を追加したいことがあるかもしれません。そういうときには ModelAdmin の Media インナークラスを使用します: class ArticleAdmin ( admin . ModelAdmin ): class Media : css = { "all" : [ "my_styles.css" ], ... ... フィールドに別のウィジェットを使用したい場合は、フィールド定義で widget 引数を使用できます。例えば: from django import forms class CommentForm ( forms . Form ): name = forms . CharField () url = forms . URLField () comment = forms . CharField ( widget = ... CES = [ "1980" , "1981" , "1982" ] FAVORITE_COLORS_CHOICES = { "blue" : "Blue" , "green" : "Green" , "black" : "Black" , } class SimpleForm ( forms . Form ): birth_year = forms . DateField ( widget = forms . SelectDateWidget ( years = BIRTH_YEAR_CHOIC ... javascript ) 、およびより詳細にカスタマイズされた見た目や動作を追加できます。 要するに、ウィジェットをサブクラス化して、 "Media" 内部クラスの定義 か "media" プロパティの作成 のどちらかをする必要があります。 これらのメソッドにはやや高度なPythonプログラ ... ... ビューを用意しています。 基本的なフォーム 以下のようなコンタクトフォームがあったとします。 forms.py from django import forms class ContactForm ( forms . Form ): name = forms . CharField () message = forms . CharField ( widget = forms . Textarea ) def se ... iew を使うことで構築できます。 views.py from myapp.forms import ContactForm from django.views.generic.edit import FormView class ContactFormView ( FormView ): template_name = "contact.html" form_class = ContactForm success_url = "/thanks/" def form_va ... ixin : """ Mixin to add JSON support to a form. Must be used with an object-based FormView (e.g. CreateView). """ accepted_media_types = [ "text/html" , "application/json" ] def dispatch ( self , request , * args , ** kwargs ): if request . get_prefer ... ... ファイル (画像、JavaScript、CSS など) を管理する を参照してください。 デフォルトでは、Django は MEDIA_ROOT と MEDIA_URL の設定を使って、ファイルをローカルに保存します。以下の例では、これらのデフォルトを使うことを前提にしてい ... に使える API を提供します。 次のモデルを考えてみましょう。 ImageField を使って写真を保存します: from django.db import models class Car ( models . Model ): name = models . CharField ( max_length = 255 ) price = models . DecimalField ( max_digits = 5 , de ... Chevy" ) >>> car . photo <ImageFieldFile: cars/chevy.jpg> >>> car . photo . name 'cars/chevy.jpg' >>> car . photo . path '/media/cars/chevy.jpg' >>> car . photo . url 'https://media.example.com/cars/chevy.jpg' このオブジェクト(例では car.photo )は F ... ... requests, but that hasn't prevented a few fairly significant new features from landing, including: A framework for writing class-based views . Built-in support for using Python's logging facilities . Contrib support for easy handling of static files . ... r the release of Django 1.3. Django 1.3 の新機能 クラスを使ったビュー Django 1.3 adds a framework that allows you to use a class as a view. This means you can compose a view out of a collection of methods that can be subclassed and overridden to provi ... les handling Django 1.3 ships with a new contrib app -- django.contrib.staticfiles -- to help developers handle the static media files (images, CSS, JavaScript, etc.) that are needed to render a complete web page. In previous versions of Django, it wa ... ... itimately deep geometries, since doing so reduces protection against fatal errors. フォームフィールド クラス GeometryField class GeometryField [ソース] PointField class PointField [ソース] LineStringField class LineStringField [ソース] PolygonField cl ... ass PolygonField [ソース] MultiPointField class MultiPointField [ソース] MultiLineStringField class MultiLineStringField [ソース] MultiPolygonField class MultiPolygonFiel ... 上でホストされている ol.js および ol.css ファイルを読み込みます。これらのファイルは、ウィジェットをサブクラス化し、内部の Media クラスの js および css プロパティを設定することで上書きできます( 定数として定義されたアセット を参照)。 CSP を適用する外 ... ... go 1.4 supports integration with in-browser testing frameworks like Selenium . The new django.test.LiveServerTestCase base class lets you test the interactions between your site's front and back ends more comprehensively. See the documentation for mor ... nes now only allow those actions for which the user has permission. For ManyToMany relationships with an auto-created intermediate model (which does not have its own permissions), the change permission for the related model determines if the user has ... form wizard The previous FormWizard from django.contrib.formtools has been replaced with a new implementation based on the class-based views introduced in Django 1.3. It features a pluggable storage API and doesn't require the wizard to pass around hi ... ... old-style of middleware described in DEP 0005 . You'll need to adapt old, custom middleware and switch from the MIDDLEWARE_CLASSES setting to the new MIDDLEWARE setting to take advantage of the improvements. Unicode ユーザー名の公式サポート The User m ... ため、必要な場合に Content-Security-Policy HTTP ヘッダーを有効にすることができるようになりました。 The new InlineModelAdmin.classes attribute allows specifying classes on inline fieldsets. Inlines with a collapse class will be initially collapsed and t ... it easier to implement custom storages that don't use the os.path calls previously in FileField . フォーム Form and widget Media is now served using django.contrib.staticfiles if installed. The <input> tag rendered by CharField now includes a minlengt ... 2026年10月08日