Skip to content

Commit 8b0e6ac

Browse files
gavinwahlacatton
authored andcommitted
Only set related_name on ProxyGenericRelation when absolutely necessary
To work around Django bugs in <1.6. Fixes #204 for Django >= 1.6. (cherry picked from commit 18582c7) This merges #264 and fixes #204. Reviewed-By: Antoine Catton <[email protected]>
1 parent a9e4cb9 commit 8b0e6ac

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

tests/modeltests/core_tests/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,9 @@ class ReviewedVersionedPage(models.Model):
256256
root_choices=[Layout, AnotherLayout],
257257
to='review_queue.ReviewedVersionTracker',
258258
)
259+
260+
261+
# This just tests that it is possible to have two widgets of the same name in
262+
# different apps.
263+
class Button(Content):
264+
pass

widgy/generic/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def get_content_type(self, obj=None, id=None, using=None):
3535

3636

3737
class ProxyGenericRelation(generic.GenericRelation):
38+
def __init__(self, *args, **kwargs):
39+
# work around django #16920, #16913
40+
kwargs.setdefault('related_name', '%(app_label)s_%(class)s_set')
41+
super(ProxyGenericRelation, self).__init__(*args, **kwargs)
42+
3843
def get_content_type(self):
3944
"""
4045
Returns the content type associated with this field's model.

widgy/models/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ class Content(models.Model):
399399
"""
400400
_nodes = ProxyGenericRelation(Node,
401401
content_type_field='content_type',
402-
object_id_field='content_id',
403-
related_name='%(app_label)s_%(class)s_set')
402+
object_id_field='content_id')
403+
404404

405405
# these preferences only affect the frontend interface and editing through
406406
# the API

0 commit comments

Comments
 (0)