Skip to content

Commit 99fa552

Browse files
fix: Fix signature for GenericRelation (typeddjango#90)
Without this, invalid signature from ForeignObject was used.
1 parent 90fc353 commit 99fa552

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

django-stubs/contrib/contenttypes/fields.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class GenericRelation(ForeignObject[Any]):
8484
content_type_field_name: Any = ...
8585
for_concrete_model: Any = ...
8686
to_fields: Any = ...
87+
def __new__(
88+
cls,
89+
*args: Any,
90+
**kwargs: Any
91+
) -> GenericRelation: ...
8792
def __init__(
8893
self,
8994
to: Union[Type[Model], str],

tests/trout/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import psycopg2
1010
from django.contrib.auth.models import User as AuthUser
11+
from django.contrib.contenttypes.fields import GenericRelation
1112
from django.contrib.postgres.fields import (
1213
ArrayField,
1314
CICharField,
@@ -234,6 +235,12 @@ class Comment(models.Model):
234235
null=True
235236
)
236237

238+
generic_relation = GenericRelation(
239+
"Post",
240+
content_type_field="generic_ct",
241+
object_id_field="generic_id",
242+
)
243+
237244

238245
def process_non_nullable(
239246
x: Union[

0 commit comments

Comments
 (0)