mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 20:24:31 +08:00
Fix ForeignKey type for self-reference defined in the abstract model (#200)
This commit is contained in:
@@ -623,4 +623,28 @@
|
||||
class TransactionLog(models.Model):
|
||||
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE)
|
||||
|
||||
Transaction().test()
|
||||
Transaction().test()
|
||||
|
||||
|
||||
- case: resolve_primary_keys_for_foreign_keys_with_abstract_self_model
|
||||
main: |
|
||||
from myapp.models import User
|
||||
reveal_type(User().parent) # N: Revealed type is 'myapp.models.User*'
|
||||
reveal_type(User().parent_id) # N: Revealed type is 'builtins.int*'
|
||||
|
||||
reveal_type(User().parent2) # N: Revealed type is 'Union[myapp.models.User, None]'
|
||||
reveal_type(User().parent2_id) # N: Revealed type is 'Union[builtins.int, None]'
|
||||
installed_apps:
|
||||
- myapp
|
||||
files:
|
||||
- path: myapp/__init__.py
|
||||
- path: myapp/models.py
|
||||
content: |
|
||||
from django.db import models
|
||||
class AbstractUser(models.Model):
|
||||
parent = models.ForeignKey('self', on_delete=models.CASCADE)
|
||||
parent2 = models.ForeignKey('self', null=True, on_delete=models.CASCADE)
|
||||
class Meta:
|
||||
abstract = True
|
||||
class User(AbstractUser):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user