per page, with , order by , clip by
Results of 1 - 10 of about 212 for import (0.009 sec.)
データベース関数 10263
データベース関数 The classes documented below provide a way for users to use functions provided by the underlying database as annotations, aggregations, or filters in Django. Functions are also expressions , so they can be used and combined ... tput_field ) [ソース] 式 expression の結果の型を output_field の型に強制的に変更します。 使用例: >>> from django.db.models import FloatField >>> from django.db.models.functions import Cast >>> Author . objects . create ( age = 25 , name = "Margaret Smi ... 混在するとデータベースエラーになります。 使用例: >>> # Get a screen name from least to most public >>> from django.db.models import Sum >>> from django.db.models.functions import Coalesce >>> Author . objects . create ( name = "Margaret Smith" , goes_by ... の値は、明示的に正しいデータベース型にキャストされない限り、不正な型に変換される可能性があります: >>> from django.db.models import DateTimeField >>> from django.db.models.functions import Cast , Coalesce >>> from django.utils import timezone >>> now = t ...
https://man.mtool.work/django/6.1/ref/models/database-functions.html
Coding style 8964
Coding style Please follow these coding standards when writing code for inclusion in Django. Pre-commit checks pre-commit is a framework for managing pre-commit hooks. These hooks help to identify simple issues before committing code for re ... {**x, **y} ) or sequences ( [*a, *b] ). This improves performance, readability, and maintainability while reducing errors. Imports Use isort to automate import sorting using the guidelines below. Quick start: /  $ python -m pip install "isort >= 7.0 ... ort recursively from your current directory, modifying any files that don't conform to the guidelines. If you need to have imports out of order (to avoid a circular import, for example) use a comment like this: import module # isort:skip Put imports in ... omponents, local Django component, try/excepts. Sort lines in each group alphabetically by the full module name. Place all import module statements before from module import objects in each section. Use absolute imports for other Django components and ...
https://man.mtool.work/django/6.1/internals/contributing/writing-code/coding-sty...
フォームセット (Formset) 8194
フォームセット (Formset) class BaseFormSet [ソース] フォームセットは、同じページで複数のフォームを扱うための抽象レイヤーです。データグリッドに例えるとわかりやすいでしょう。次のようなフォームがあるとしましょう: >>> from django import forms > ... 成できるようにしたいと思うかもしれません。 ArticleForm からフォームセットを作るには、次のようにします: >>> from django.forms import formset_factory >>> ArticleFormSet = formset_factory ( ArticleForm ) これで ArticleFormSet という名前のフォームセットクラス ... セットが初期データから生成するフォームに加え、追加で表示するフォームの数を指定することを意味します。例を見てみましょう: >>> import datetime >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset ... formset_factory() に max_num パラメータを渡すと、フォームセットが表示するフォームの数を制限できます: >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory ( ArticleForm , extra = 2 , m ...
https://man.mtool.work/django/6.1/topics/forms/formsets.html
翻訳 8194
翻訳 概要 Django プロジェクトを翻訳可能にするためには、Python コードやテンプレートに、多少のフックを加筆しなければなりません。このフックは 翻訳文字列 と呼ばれます。翻訳文字列は Django に「このテキストに対する翻訳が有効な場合、このテキストは ... のため、グローバル名前空間に _() をインストールすると、干渉して問題を引き起こします。 gettext() を _() という名前で明示的に import すれば、この問題を回避できます。 _ として別名をつけられる関数は? ( makemessages で使われる) xgettext が動作する方法のせいで ... 、単一の文字列引数を持つ関数のみが _ として import できます。 gettext() gettext_lazy() この例では、 "Welcome to my site." というテキストが翻訳文字列としてマークされています: ... from django.http import HttpResponse from django.utils.translation import gettext as _ def my_view ( request ): output = _ ( "Welcome to my site." ...
https://man.mtool.work/django/6.1/topics/i18n/translation.html
ジェネリック日付ビュー 8077
ジェネリック日付ビュー 日付ベースのジェネリックビュー ( django.views.generic.dates 内で提供されています) は、日付ベースのデータのために、ドリルダウンページを描画するためのビューです。 注釈 このページの例のいくつかは、 myapp/models.py 内で下 ... 記の通り Article モデルが定義されていると仮定します: from django.db import models from django.urls import reverse class Article ( models . Model ): title = models . CharField ( max_length = 200 ) p ... d 属性を用いた月や日に変更できます。これは、すべてのサブクラスのビューに適用されます。 例 myapp/urls.py : from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path ( "arch ... ます。 ノート デフォルトの template_name_suffix は _archive_year です。 例 myapp/views.py : from django.views.generic.dates import YearArchiveView from myapp.models import Article class ArticleYearArchiveView ( YearArchiveView ): queryset = Article . ob ...
https://man.mtool.work/django/6.1/ref/class-based-views/generic-date-based.html
Django の admin サイト 8077
Django の admin サイト Django のパワフルな特徴の1つは、自動的に生成される admin インタフェースです。あなたのモデルクラスからメタデータを読み取り、モデル中心のインタフェースを提供します。このインタフェースのおかげで、ユーザはあなたのサイトの ... 表現する方法です。通常、アプリケーション内の admin.py に記述されます。 ModelAdmin の例を見てみましょう: from django.contrib import admin from myapp.models import Author class AuthorAdmin ( admin . ModelAdmin ): pass admin . site . register ( Author , Au ... くありません。ModelAdminの記述をせずにモデルクラスを登録できます。上記の例は、次のように簡略化できます。 from django.contrib import admin from myapp.models import Author admin . site . register ( Author ) register デコレータ register ( * models , site = ... django.contrib.admin.sites.site ) [ソース] ModelAdmin を登録するために、デレコータも用意されています: from django.contrib import admin from .models import Author @admin . register ( Author ) class AuthorAdmin ( admin . ModelAdmin ): pass 1 つ以上のモデ ...
https://man.mtool.work/django/6.1/ref/contrib/admin/
URL ディスパッチャ 8035
URL ディスパッチャ すっきりした、簡潔で明解な URL スキームは、高品質な Web アプリケーションでは重要な要素です。 Django では、フレームワークの制限なしに、望み通りの URL を設計できます。 URL はすっきりした扱いやすいものにすべきであるという主張 ... た URL にマッチする最初のパターンで停止します。 ある 1 個の正規表現にマッチしたら、 Django はマッピングで指定されたビューを import して呼び出します。そのビューは Python 関数 (もしくは クラスベースのビュー ) です。ビューには以下の引数が渡されます: HttpRe ... ドリングビューを呼び出します。下の Error handling を見てください。 カスタマイズ例 URLconf のサンプルです。 from django.urls import path from . import views urlpatterns = [ path ( "articles/2003/" , views . special_case_2003 ), path ( "articles/<int:year ... eturn " %04d " % value register_converter() : を使用して、URLconf にカスタムコンバータクラスを登録します: from django.urls import path , register_converter from . import converters , views register_converter ( converters . FourDigitYearConverter , "yyy ...
https://man.mtool.work/django/6.1/topics/http/urls.html
クラスベースのビューでフォームを扱う 7623
クラスベースのビューでフォームを扱う フォームの処理には、一般に3つの場合分けが存在します。 最初の GET リクエスト (空白またはデフォルト値が埋め込まれたフォームを返す) 無効なデータの POST リクエスト (よくあるパターンは、エラー表示を追加したフ ... 般的なクラスビューを用意しています。 基本的なフォーム 以下のようなコンタクトフォームがあったとします。 forms.py from django import forms class ContactForm ( forms . Form ): name = forms . CharField () message = forms . CharField ( widget = forms . Texta ... ing the self.cleaned_data dictionary pass このとき、ビューは FormView を使うことで構築できます。 views.py from myapp.forms import ContactForm from django.views.generic.edit import FormView class ContactFormView ( FormView ): template_name = "contact.ht ... ても、モデルを指定する必要があります。 First we need to add get_absolute_url() to our Author class: models.py from django.db import models from django.urls import reverse class Author ( models . Model ): name = models . CharField ( max_length = 200 ) def ...
https://man.mtool.work/django/6.1/topics/class-based-views/generic-editing.html
組み込みのクラスベースのジェネリックビュー(汎用ビュー) 7549
組み込みのクラスベースのジェネリックビュー(汎用ビュー) ウェブアプリケーションを書くのは、特定のパターンを何度も繰り返すことになるため、単調になりがちです。Django はモデルとテンプレート層で単調さを取り除くことを試みてきましたが、ウェブ開発 ... トや個々のオブジェクトを表示する例から見てみましょう。 ここでは、以下のようなモデルを使用します。 # models.py from django.db import models class Publisher ( models . Model ): name = models . CharField ( max_length = 30 ) address = models . CharField ( ma ... s . CASCADE ) publication_date = models . DateField () 次に、ビューを定義しましょう。 # views.py from django.views.generic import ListView from books.models import Publisher class PublisherListView ( ListView ): model = Publisher 最後に、このビューを U ... RL にフックさせます。 # urls.py from django.urls import path from books.views import PublisherListView urlpatterns = [ path ( "publishers/" , PublisherListView . as_view ()), ] 書 ...
https://man.mtool.work/django/6.1/topics/class-based-views/generic-display.html
モデルからフォームを作成する 7465
モデルからフォームを作成する ModelForm class ModelForm [ソース] データベース中心のアプリケーションを作成している場合、Django モデルに密接にマップするフォームを使うことになるでしょう。例えば、 BlogComment モデルを持っていて、閲覧者がコメント ... o モデルから Form クラスを生成できるようなヘルパークラスを用意してあります。 例えば次のようにします: >>> from django.forms import ModelForm >>> from myapp.models import Article # Create the form class. >>> class ArticleForm ( ModelForm ): ... class Met ... erriding the default fields を参照してください。 完全な具体例 以下のような一連のモデルを考えていきましょう: from django.db import models from django.forms import ModelForm TITLE_CHOICES = { "MR" : "Mr." , "MRS" : "Mrs." , "MS" : "Ms." , } class Author ... の ModelForm サブクラスはおおむね以下と同等と言えます (唯一の違いは save() メソッドで、これからすぐ説明します): from django import forms class AuthorForm ( forms . Form ): name = forms . CharField ( max_length = 100 ) title = forms . CharField ( max_len ...
https://man.mtool.work/django/6.1/topics/forms/modelforms.html
PREV 1 2 3 4 5 6 7 8 9 10 NEXT