django-parler / django-parler-rest

Translatable model support for django-rest-framework
Apache License 2.0
59 stars 16 forks source link

Why TranslatedFieldsField assumes there is a parent.Meta.model? #17

Open kemar opened 8 years ago

kemar commented 8 years ago

Hi,

I have a question regarding this commit : https://github.com/django-parler/django-parler-rest/commit/5e9cc0432f902334665cfc3bb1a8b5a0c6677dfc

Sometimes we don't inherit from a ModelSerializer, e.g.:

class TemplateSerializer(drf_serializers.Serializer):
    translations = parler_serializers.TranslatedFieldsField(shared_model=models.Template)

The above mentioned commit breaks non-ModelSerializer:

AttributeError: 'FileSerializer' object has no attribute 'Meta'

Is there a valid reason why TranslatedFieldsField assumes there is a parent.Meta.model?

vdboor commented 8 years ago

The TranslatedFieldsField only works on a TranslatableModelSerializer, see the example in the README. Both need to work together, as serialize fields can't control the model .save() call sadly.

I've highlighted this fact in the readme now.

vdboor commented 8 years ago

Sorry, after closing reading I see you're trying to create a "mixin" or base class. I've moved the checks of the parent.Meta.model to the actual place they are used, instead of checking them too early (see 9a3dd7c8de264a93d26f4f21c1675a748ae56d29). Does this work for you?