#29466: Textual "to" parameter of ForeignKey fails to resolve if placed in 
abstract
model
-------------------------------------+-------------------------------------
               Reporter:  Vitalik    |          Owner:  nobody
  Verhovodov                         |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 {{{#!python
 import django
 from django.conf import settings

 settings.configure(DEBUG=True)
 django.setup()

 from django.db import models


 SHOULD_I_FAIL = True  # switch this to reproduce the bug


 class ReferencedModel(models.Model):
     field = models.FloatField()

     class Meta:
         app_label = 'myapp'


 ref = 'ReferencedModel' if SHOULD_I_FAIL else ReferencedModel


 class AbstractModel(models.Model):
     # NOTE: only abstract models are affected
     field = models.ForeignKey(ref, on_delete=models.CASCADE)

     class Meta:
         abstract = True
         app_label = 'myapp'


 class RealModel(AbstractModel):
     other_field = models.CharField(max_length=100)

     class Meta:
         app_label = 'myapp'


 ffield = AbstractModel._meta.get_field('field')
 # ValueError: Related model 'ReferencedModel' cannot be resolved
 print(ffield.target_field)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29466>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.d651307b32eebbd7b8e99886d0b956c7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to