From 0a3cb4a50ddf22ed14030f16119998aeb604e9bb Mon Sep 17 00:00:00 2001
From: Anthony Sottile <asottile@umich.edu>
Date: Tue, 10 Sep 2024 12:57:07 -0400
Subject: [PATCH] add cache_name for django 5.1 (#2365)

---
 django-stubs/contrib/contenttypes/fields.pyi | 1 -
 django-stubs/db/models/fields/mixins.pyi     | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi
index ac38dd867..27661d6f7 100644
--- a/django-stubs/contrib/contenttypes/fields.pyi
+++ b/django-stubs/contrib/contenttypes/fields.pyi
@@ -42,7 +42,6 @@ class GenericForeignKey(FieldCacheMixin):
     def get_filter_kwargs_for_object(self, obj: Model) -> dict[str, ContentType | None]: ...
     def get_forward_related_filter(self, obj: Model) -> dict[str, int]: ...
     def check(self, **kwargs: Any) -> list[CheckMessage]: ...
-    def get_cache_name(self) -> str: ...
     def get_content_type(
         self, obj: Model | None = ..., id: int | None = ..., using: str | None = ..., model: type[Model] | None = ...
     ) -> ContentType: ...
diff --git a/django-stubs/db/models/fields/mixins.pyi b/django-stubs/db/models/fields/mixins.pyi
index 28521f099..a77d09fb5 100644
--- a/django-stubs/db/models/fields/mixins.pyi
+++ b/django-stubs/db/models/fields/mixins.pyi
@@ -1,11 +1,14 @@
 from typing import Any
 
 from django.db.models.base import Model
+from django.utils.functional import cached_property
 
 NOT_PROVIDED: Any
 
 class FieldCacheMixin:
     def get_cache_name(self) -> str: ...
+    @cached_property
+    def cache_name(self) -> str: ...
     def get_cached_value(self, instance: Model, default: Any = ...) -> Model | None: ...
     def is_cached(self, instance: Model) -> bool: ...
     def set_cached_value(self, instance: Model, value: Model | None) -> None: ...