... -|--------|--------| | foo | 1 | 13 | | bar | 2 | (null) | | test | 3 | 13 | 汎用的な集計関数の例をいくつか紹介します: >>> TestModel . objects . aggregate ( result = StringAgg ( "field1" , delimiter = ";" )) {'result': 'foo;bar;test'} >>> TestModel . obje ... cts . aggregate ( result = ArrayAgg ( "field2" )) {'result': [1, 2, 3]} >>> TestModel . objects . aggregate ( result = ArrayAgg ( "field1" )) {'result': ['foo', 'bar', 'test']} 次の例では、統計的集計関数の使い ... 方を示します。基礎となる数学については説明しません (たとえば、 wikipedia で読むことができます): >>> TestModel . objects . aggregate ( count = RegrCount ( y = "field3" , x = "field2" )) {'count': 2} >>> TestModel . objects . aggregat ... ... solate_apps class MyModelTests ( SimpleTestCase ): @isolate_apps ( "app_label" ) def test_model_definition ( self ): class TestModel ( models . Model ): pass ... あるいは、次のようにします。 with isolate_apps ( "app_label" ): class TestModel ( models . Mo ... 使用する際に attr_name パラメータを使用して属性として取得できます。 @isolate_apps ( "app_label" , attr_name = "apps" ) class TestModelDefinition ( SimpleTestCase ): def test_model_definition ( self ): class TestModel ( models . Model ): pass self . assertIs ... ( self . apps . get_model ( "app_label" , "TestModel" ), TestModel ) あるいは、 kwarg_name パラメータを使ってメソッドデコレータとして使用する際に、 テストメソッドの引数として指 ... ... ator: from django.db import models from django.test import SimpleTestCase from django.test.utils import isolate_apps class TestModelDefinition ( SimpleTestCase ): @isolate_apps ( "app_label" ) def test_model_definition ( self ): class TestModel ( models . ... ts.py from django.db import models from django.test import SimpleTestCase from django.test.utils import isolate_apps class TestModelDefinition ( SimpleTestCase ): @isolate_apps ( "app_label" , "other_app_label" ) def test_model_definition ( self ): # This ... model automatically receives app_label='app_label' class TestModel ( models . Model ): pass class OtherAppModel ( models . Model ): class Meta : app_label = "other_app_label" ... ... 2026年10月08日