diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index ca4f4368b6..fad5560486 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -978,6 +978,9 @@ class ForeignKey(ForeignObject): ) self.db_constraint = db_constraint + def __class_getitem__(cls, *args, **kwargs): + return cls + def check(self, **kwargs): return [ *super().check(**kwargs), diff --git a/tests/model_fields/test_foreignkey.py b/tests/model_fields/test_foreignkey.py index a5b646ae86..ca8eff3540 100644 --- a/tests/model_fields/test_foreignkey.py +++ b/tests/model_fields/test_foreignkey.py @@ -164,3 +164,6 @@ class ForeignKeyTests(TestCase): class MyModel(models.Model): child = models.ForeignKey(1, models.CASCADE) + + def test_manager_class_getitem(self): + self.assertIs(models.ForeignKey["Foo"], models.ForeignKey)