mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #17648 -- Add for_concrete_model
to GenericForeignKey
.
Allows a `GenericForeignKey` to reference proxy models. The default for `for_concrete_model` is `True` to keep backwards compatibility. Also added the analog `for_concrete_model` kwarg to `generic_inlineformset_factory` to provide an API at the form level.
This commit is contained in:
parent
8dda8a5ecc
commit
48424adaba
6 changed files with 179 additions and 17 deletions
|
@ -102,3 +102,22 @@ class Rock(Mineral):
|
|||
class ManualPK(models.Model):
|
||||
id = models.IntegerField(primary_key=True)
|
||||
tags = generic.GenericRelation(TaggedItem)
|
||||
|
||||
|
||||
class ForProxyModelModel(models.Model):
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
obj = generic.GenericForeignKey(for_concrete_model=False)
|
||||
title = models.CharField(max_length=255, null=True)
|
||||
|
||||
class ForConcreteModelModel(models.Model):
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
obj = generic.GenericForeignKey()
|
||||
|
||||
class ConcreteRelatedModel(models.Model):
|
||||
bases = generic.GenericRelation(ForProxyModelModel, for_concrete_model=False)
|
||||
|
||||
class ProxyRelatedModel(ConcreteRelatedModel):
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue