Skip to content

Commit

Permalink
Small changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Nov 19, 2013
1 parent 37d7d2a commit 939739c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion playhouse/djpeewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def _translate_model(self,
attrs[model_field.name] = IntegerField(
db_column=model_field.get_attname())
else:
related_name = model_field.related_query_name()
related_name = (model_field.rel.related_name or
model_field.related_query_name())
if related_name.endswith('+'):
related_name = '__%s:%s:%s' % (
options,
Expand Down
19 changes: 19 additions & 0 deletions playhouse/tests_djpeewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class B(models.Model):
class C(models.Model):
b = models.ForeignKey(B, related_name='cs')

class Parent(models.Model):
pass

class Child(Parent):
pass


class TestDjPeewee(unittest.TestCase):
def assertFields(self, model, expected):
self.assertEqual(len(model._meta.fields), len(expected))
Expand Down Expand Up @@ -239,6 +246,18 @@ def test_backrefs(self):
'Post',
'User'])

def test_inheritance(self):
trans = translate(Parent)
self.assertEqual(trans.keys(), ['Parent'])
self.assertFields(trans['Parent'], [
('id', PrimaryKeyField),])

trans = translate(Child)
self.assertEqual(sorted(trans.keys()), ['Child', 'Parent'])
self.assertFields(trans['Child'], [
('id', PrimaryKeyField),
('parent_ptr', ForeignKeyField)])


else:
print_('Skipping djpeewee tests, Django not found.')

0 comments on commit 939739c

Please sign in to comment.