Skip to content

Commit 7253a9f

Browse files
author
Mike Hearing
committed
Temporary fix for binding data to model instance where slug_field is not provided on __init__
1 parent a23a1cf commit 7253a9f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pyrestorm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.0'
1+
__version__ = '0.2.1'

pyrestorm/models.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ def __init__(self, *args, **kwargs):
8989

9090
# Bind to the name of the field a `RestQueryset` of the correct type
9191
for name, field in self._meta.related_fields.iteritems():
92-
setattr(
93-
self,
94-
name,
95-
field.to.objects.get_queryset_class(
96-
url='/'.join([self.get_absolute_url().rstrip('/'), field.url, ''])
92+
# Don't rebind data which already exists
93+
if hasattr(self, self._meta.slug_field) is True:
94+
setattr(
95+
self,
96+
name,
97+
field.to.objects.get_queryset_class(
98+
url='/'.join([self.get_absolute_url().rstrip('/'), field.url, ''])
99+
)
97100
)
98-
)
99101

100102
# Manager to act like Django ORM
101103
objects = RestOrmManager
@@ -226,7 +228,7 @@ def get_base_url(cls, bits=[]):
226228

227229
# Returns the URL to this resource
228230
def get_absolute_url(self):
229-
return self.get_base_url(bits=[unicode(getattr(self, self._meta.slug_field)), ])
231+
return self.get_base_url(bits=[unicode(getattr(self, self._meta.slug_field, '')), ])
230232

231233
# Does not save nested keys
232234
def save(self, raise_exception=False, **kwargs):

0 commit comments

Comments
 (0)