#36183: Model o2o inheritance with abstract models does not "evaluate" a lazy
relationship
-------------------------------------+-------------------------------------
     Reporter:  BeryCZ               |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  5.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

 Your `AbstractPageType` definition is invalid as it's not allowed to
 define a `parent_link` on a model that doesn't directly inherit from the
 referenced model even when abstract.

 The correct way to do this is to have the abstract model defining the
 parent link subclass the concrete model (abstract MTI). This means you
 should be able to achieve what you're after by re-organizing your model
 definition to make sure `AbstractPageType` does inherit from `Page`

 {{{#!python
 class AbstractPage(models.Model):
     mtime = models.DateTimeField(
         verbose_name="Last modification at",
         auto_now=True,
     )

     class Meta:
         abstract = True

 class Page(AbstractPage):
     number = models.IntegerField()

 class AbstractPageType(Page):
     page = models.OneToOneField(
         "Page",
         verbose_name="ID",
         primary_key=True,
         on_delete=models.CASCADE,
         related_name="%(class)s",
         parent_link=True,
     )

     class Meta:
         abstract = True

 class ArticlePage(AbstractPageType):
     pass

 class OtherPage(AbstractPageType):
     pass
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36183#comment:3>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070194fcfedde6-5c4a1d89-ef94-4b86-8edf-d07d57509485-000000%40eu-central-1.amazonses.com.

Reply via email to