per page, with , order by , clip by
Results of 1 - 10 of about 58 for Author (0.006 sec.)
データベース関数 12280
データベース関数 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 ... regate functions . See the Func documentation for security considerations. 各関数の例では、以下のモデルを使用します: class Author ( models . Model ): name = models . CharField ( max_length = 50 ) age = models . PositiveIntegerField ( null = True , blan ... 強制的に変更します。 使用例: >>> from django.db.models import FloatField >>> from django.db.models.functions import Cast >>> Author . objects . create ( age = 25 , name = "Margaret Smith" ) >>> author = Author . objects . annotate ( ... age_as_float = Ca ... st ( "age" , output_field = FloatField ()), ... ) . get () >>> print ( author . age_as_float ) 25.0 Coalesce class Coalesce ( * expressions , ** extra ) [ソース] 少なくとも2つのフィールド名または式のリ ...
https://man.mtool.work/django/6.1/ref/models/database-functions.html
モデルからフォームを作成する 12148
モデルからフォームを作成する ModelForm class ModelForm [ソース] データベース中心のアプリケーションを作成している場合、Django モデルに密接にマップするフォームを使うことになるでしょう。例えば、 BlogComment モデルを持っていて、閲覧者がコメント ... import models from django.forms import ModelForm TITLE_CHOICES = { "MR" : "Mr." , "MRS" : "Mrs." , "MS" : "Ms." , } class Author ( models . Model ): name = models . CharField ( max_length = 100 ) title = models . CharField ( max_length = 3 , choices = ... e ) def __str__ ( self ): return self . name class Book ( models . Model ): name = models . CharField ( max_length = 100 ) authors = models . ManyToManyField ( Author ) class AuthorForm ( ModelForm ): class Meta : model = Author fields = [ "name" , "ti ... tle" , "birth_date" ] class BookForm ( ModelForm ): class Meta : model = Book fields = [ "name" , "authors" ] これらのモデルでは、上記の ModelForm サブクラスはおおむね以下と同等と言えます (唯一の違いは save() メソッドで、これから ...
https://man.mtool.work/django/6.1/topics/forms/modelforms.html
配信 (syndication) フィード フレームワーク 11665
配信 (syndication) フィード フレームワーク Django には、 RSS と Atom フィードを作成するための高レベルな配信 (syndication) フィード生成フレームワークが付属しています。 任意の配信フィードを作成するには、短い Python クラスを書くだけで済みます。 ... """ Returns the feed's description as a normal Python string. """ description = "Foo bar baz." # Hard-coded description. # AUTHOR NAME --One of the following three is optional. The framework # looks for them in this order. def author_name ( self , obj ... ): """ Takes the object returned by get_object() and returns the feed's author's name as a normal Python string. """ def author_name ( self ): """ Returns the feed's author's name as a normal Python st ... ring. """ author_name = "Sally Smith" # Hard-coded author name. # AUTHOR EMAIL --One of the following three is optional. The framework # lo ...
https://man.mtool.work/django/6.1/ref/contrib/syndication.html
クラスベースのビューでフォームを扱う 10611
クラスベースのビューでフォームを扱う フォームの処理には、一般に3つの場合分けが存在します。 最初の GET リクエスト (空白またはデフォルト値が埋め込まれたフォームを返す) 無効なデータの POST リクエスト (よくあるパターンは、エラー表示を追加したフ ... 合、 form_class が ModelForm だったとしても、モデルを指定する必要があります。 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 = mode ... ls . CharField ( max_length = 200 ) def get_absolute_url ( self ): return reverse ( "author-detail" , kwargs = { "pk" : self . pk }) そうしたら、 CreateView およびその仲間たちを使って実際に動作させることができます。 ... ls import reverse_lazy from django.views.generic.edit import CreateView , DeleteView , UpdateView from myapp.models import Author class AuthorCreateView ( CreateView ): model = Author fields = [ "name" ] class AuthorUpdateView ( UpdateView ): model = A ...
https://man.mtool.work/django/6.1/topics/class-based-views/generic-editing.html
ジェネリック編集ビュー (Generic editing view) 10011
ジェネリック編集ビュー (Generic editing view) 以下のビューは、このページで説明され、内容を編集するための基礎を提供します: django.views.generic.edit.FormView django.views.generic.edit.CreateView django.views.generic.edit.UpdateView django.vi ... SuccessMessageMixin が含まれており、フォーム送信の成功に関するメッセージを表示できます。 注釈 このページの例のいくつかは、 Author モデルが下記の通り myapp/models.py 内で定義されているものと見なしています。 from django.db import models from django.urls ... import reverse class Author ( models . Model ): name = models . CharField ( max_length = 200 ) def get_absolute_url ( self ): return reverse ( "author ... ストに描画された CreateView のページは、 '_form' の template_name_suffix を使います。 例えば、この属性をオブジェクト (例えば Author モデル) を作成するビューのために '_create_form' に変更すると、 デフォルトの template_name は 'myapp/author_create_form.htm ...
https://man.mtool.work/django/6.1/ref/class-based-views/generic-editing.html
Fetch modes 9484
Fetch modes New in Django 6.1. When accessing model fields that were not loaded as part of the original query, Django will fetch that field's data from the database. You can customize the behavior of this fetching with a fetch mode , making ... mode> . Django provides three fetch modes. We'll explain them below using these models: from django.db import models class Author ( models . Model ): ... class Book ( models . Model ): author = models . ForeignKey ( Author , on_delete = models . CASCAD ... E ) ... …and this loop: for book in books : print ( book . author . name ) …where books is a QuerySet of Book instances using some fetch mode. FETCH_ONE Fetches the missing field for the c ... NE for the above example would use: 1 query to fetch books N queries, where N is the number of books, to fetch the missing author field …for a total of 1+N queries. This query pattern is known as the "N+1 queries problem" because it often leads to perf ...
https://man.mtool.work/django/6.1/topics/db/fetch-modes.html
全文検索 8914
全文検索 django.contrib.postgres.search モジュールのデータベース関数は PostgreSQL の 全文検索エンジン を利用しやすくしています。 このドキュメントの例では、 クエリを作成する で定義されたモデルを使用します。 参考 検索の概要については、 トピッ ... す。2つの引数の間の trigram 類似度を返します。 使用例: >>> from django.contrib.postgres.search import TrigramSimilarity >>> Author . objects . create ( name = "Katy Stevens" ) >>> Author . objects . create ( name = "Stephen Keats" ) >>> test = "Katie St ... ephens" >>> Author . objects . annotate ( ... similarity = TrigramSimilarity ( "name" , test ), ... ) . filter ( ... similarity__gt = 0.3 ... ... ) . order_by ( "-similarity" ) <QuerySet [<Author: Katy Stevens>, <Author: Stephen Keats>]> TrigramWordSimilarity class TrigramWordSimilarity ( string , expression , ** ext ...
https://man.mtool.work/django/6.1/ref/contrib/postgres/search.html
検索 8738
検索 ウェブアプリケーションの一般的なタスクは、ユーザーからの入力を用いてデータベース内のデータを検索することです。簡単なケースなら、オブジェクトのリストをカテゴリごとにフィルタリングすることで実現できるかもしれません。しかし、もっと複雑なユ ... ストのクエリ Text-based fields have a selection of matching operations. For example, you may wish to allow the lookup of an author like so: >>> Author . objects . filter ( name__contains = "Terry" ) [<Author: Terry Gilliam>, <Author: Terry Jones>] これは ... ないルックアップがの方が使いやすいでしょう。英語以外の名前を扱う場合、さらなる改善は アクセントなし比較 を使うことです: >>> Author . objects . filter ( name__unaccent__icontains = "Helen" ) [<Author: Helen Mirren>, <Author: Helena Bonham Carter>, <Autho ... がヒットしますが、その逆はヒットしません。もう一つの方法は trigram_similar 比較を使うことです。 例えば次のようにします: >>> Author . objects . filter ( name__unaccent__lower__trigram_similar = "Hélène" ) [<Author: Helen Mirren>, <Author: Hélène Joy>] 今 ...
https://man.mtool.work/django/6.1/topics/db/search.html
アグリゲーション (集計) 8518
アグリゲーション (集計) Djangoのデータベース抽象API のトピックガイドでは、個別のオブジェクトの作成、取得、削除を行うDjangoのクエリの使い方を説明しました。しかし、オブジェクトのコレクションを 集計 (アグリゲーション) した値や、集計することによ ... を使用します。これらのモデルは、一連のオンライン書店の在庫を追跡するために使用されます。 from django.db import models class Author ( models . Model ): name = models . CharField ( max_length = 100 ) age = models . IntegerField () class Publisher ( models ... s . IntegerField () price = models . DecimalField ( max_digits = 10 , decimal_places = 2 ) rating = models . FloatField () authors = models . ManyToManyField ( Author ) publisher = models . ForeignKey ( Publisher , on_delete = models . CASCADE ) pubdat ... 籍の一覧を取得しようとする場合には、それぞれの書籍に寄稿している著者が何名いるのかを知りたいこともあるでしょう。 各 Book は Author に対して多対多の関係を持っています。この関係を QuerySet 内の各書籍について集計できます。 オブジェクトごとの集計は annotate ...
https://man.mtool.work/django/6.1/topics/db/aggregation.html
クラスベースのビューでミックスイン (mixin) を使用する 8357
クラスベースのビューでミックスイン (mixin) を使用する 注意 This is an advanced topic. A working knowledge of Django's class-based views is advised before exploring these techniques. Django のビルトインのクラスベースビューではたくさんの機能が ... オブジェクトに対して処理を行いたい場合、 SingleObjectMixin が提供する機能が必要になります。 We'll demonstrate this with the Author model we used in the generic class-based views introduction . views.py from django.http import HttpResponseForbidden , Htt ... t reverse from django.views import View from django.views.generic.detail import SingleObjectMixin from books.models import Author class RecordInterestView ( SingleObjectMixin , View ): """Records the current user's interest in an author.""" model = Aut ... , 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 HttpResponseRedi ...
https://man.mtool.work/django/6.1/topics/class-based-views/mixins.html
PREV 1 2 3 4 5 6 NEXT