Skip to content

Commit 3432d81

Browse files
committed
Add some precisions to documentation about REST framework version requirements and multi-table inheritance. Fixes #235.
Catch attempts to use multi-table inheritance and raise an explicit error. Closes #230.
1 parent cf4f07e commit 3432d81

6 files changed

Lines changed: 28 additions & 6 deletions

File tree

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Features
2828
* **Reliable** - more than 300 test cases and counting. |coverage| |build|
2929
* **Compatible** with Django 1.4 to 1.8, running Python 2.7, 3.3 or 3.4.
3030

31-
Django-hvad also features support for `Django REST framework`_, including
31+
Django-hvad also features support for `Django REST framework`_ 3.1 or newer, including
3232
translation-aware serializers.
3333

3434
Example Uses

docs/public/models.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ following restrictions:
187187

188188
The ``__init__`` method and signals for the concrete model will still be called.
189189

190+
Multi-table Inheritance
191+
=======================
192+
193+
Unfortunately, multi-table inheritance is not supported, and unlikely to be.
194+
Please read :issue:`230` about the issues with multi-table inheritance.
195+
190196
.. _custom-managers:
191197

192198
*****************************

docs/public/restframework.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ hvad providing the following extensions:
2020
- :ref:`TranslationsMixin` can be plugged into a `ModelSerializer` to add a
2121
dictionary of all available translations. Writing is supported as well.
2222

23+
.. note:: Support for REST framework requires Django REST Framework version 3.1
24+
or newer.
25+
2326
--------
2427

2528
.. _TranslatableModelSerializer:

hvad/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class of the translations table
7878
base = scan_bases.pop()
7979
if not issubclass(base, TranslatableModel) or base is TranslatableModel:
8080
continue
81+
if not base._meta.abstract:
82+
raise TypeError(
83+
'Multi-table inheritance of translatable models is not supported. '
84+
'Concrete model %s is not a valid base model for %s.' % (
85+
base._meta.model_name if django.VERSION >= (1, 6) else base._meta.module_name,
86+
model._meta.model_name if django.VERSION >= (1, 6) else model._meta.module_name))
8187
try:
8288
# The base may have translations model, then just inherit that
8389
translation_bases.append(base._meta.translations_model)
@@ -92,7 +98,7 @@ class of the translations table
9298
meta['db_tablespace'] = model._meta.db_tablespace
9399
meta['managed'] = model._meta.managed
94100
if model._meta.order_with_respect_to in fields:
95-
raise ImproperlyConfigured(
101+
raise ValueError(
96102
'Using a translated fields in %s.Meta.order_with_respect_to is ambiguous '
97103
'and hvad does not support it.' %
98104
model._meta.model_name if django.VERSION >= (1, 6) else model._meta.module_name)

hvad/tests/basic.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ class InvalidModel2(object):
3737
self.assertRaises(ImproperlyConfigured, type,
3838
'InvalidModel2', bases, attrs)
3939

40+
def test_multi_table_raises(self):
41+
with self.assertRaises(TypeError):
42+
class InvalidModel3(Normal):
43+
translations = TranslatedFields(
44+
other_translated = models.CharField(max_length=250)
45+
)
46+
4047
def test_order_with_respect_to_raises(self):
41-
with self.assertRaises(ImproperlyConfigured):
42-
class InvalidModel3(TranslatableModel):
48+
with self.assertRaises(ValueError):
49+
class InvalidModel4(TranslatableModel):
4350
translations = TranslatedFields(
4451
translated_field = models.CharField(max_length=250)
4552
)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from setuptools import setup, find_packages
22
from hvad import __version__ as version
33

4-
with open('README.rst') as f:
5-
long_description = f.read()
4+
with open('README.rst', 'rb') as f:
5+
long_description = f.read().decode('utf-8')
66

77
setup(
88
name = 'django-hvad',

0 commit comments

Comments
 (0)