Skip to content

Commit

Permalink
Allow proxy models in GenericForeignKey fields
Browse files Browse the repository at this point in the history
re #9588
  • Loading branch information
mdellweg authored and bmbouter committed Dec 9, 2021
1 parent c79da9c commit 3cddf3a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pulpcore/app/models/base.py
Expand Up @@ -31,7 +31,7 @@ class Label(LifecycleModel):
key = models.CharField(max_length=200, db_index=True)
value = models.TextField(null=True, db_index=True)

content_object = GenericForeignKey("content_type", "object_id")
content_object = GenericForeignKey("content_type", "object_id", for_concrete_model=False)

class Meta:
unique_together = [["content_type", "object_id", "key"]]
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/app/models/generic.py
Expand Up @@ -22,7 +22,7 @@ class GenericRelationModel(BaseModel):

content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.UUIDField()
content_object = GenericForeignKey("content_type", "object_id")
content_object = GenericForeignKey("content_type", "object_id", for_concrete_model=False)

class Meta:
abstract = True
4 changes: 2 additions & 2 deletions pulpcore/app/models/role.py
Expand Up @@ -44,7 +44,7 @@ class UserRole(BaseModel):
role = models.ForeignKey(Role, related_name="object_users", on_delete=models.CASCADE)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True)
object_id = models.CharField(max_length=255, null=True)
content_object = GenericForeignKey("content_type", "object_id")
content_object = GenericForeignKey("content_type", "object_id", for_concrete_model=False)

class Meta:
unique_together = (("user", "role", "content_type", "object_id"),)
Expand All @@ -66,7 +66,7 @@ class GroupRole(BaseModel):
role = models.ForeignKey(Role, related_name="object_groups", on_delete=models.CASCADE)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True)
object_id = models.CharField(max_length=255, null=True)
content_object = GenericForeignKey("content_type", "object_id")
content_object = GenericForeignKey("content_type", "object_id", for_concrete_model=False)

class Meta:
unique_together = (("group", "role", "content_type", "object_id"),)
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/app/serializers/user.py
Expand Up @@ -83,7 +83,7 @@ def to_internal_value(self, data):
try:
obj = NamedModelViewSet.get_resource(data)
except serializers.ValidationError:
raise serializers.ValidationError(_("Invalid value for 'obj': {}.").format(data))
raise serializers.ValidationError(_("Invalid value: {}.").format(data))
return {"content_object": obj}


Expand Down

0 comments on commit 3cddf3a

Please sign in to comment.