Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom model metaclass #188

Merged

Conversation

spectras
Copy link
Collaborator

This PR moves the code that customizes TranslatableModel subclasses from the TranslatableModelBase metaclass into a signal handler, connected to Django's builtin class_prepared. It gets triggered almost at the same point, but does not conflict with other metaclass-using apps.
We are 100% sure it gets registered in time as it is in the same module as TranslatableModel.

Here is the detailed list of changes:

  • empty out TranslatableModelBase and mark it as deprecated. Testcase checks that nothing is broken and a warning is thrown.
  • move its __new__ method to a prepare_translatable_model signal handler.
  • clean up the signal handler code: running a bit later, it needs less introspection to gather required data.
  • force _base_manager to never be an instance of TranslationManager or a subclass. This was actually missing from the metaclass code (*)
  • move the associated contribute_translations out of the model, next to the signal handler. It has no business inside the model class and polluted its namespace.

Tests pass. No behavior change was expected.

(*) it has no influence as _base_manager would only get overriden when using use_for_related_fields = True, and this override only breaks if the default_class of the queryset is set to TranslationQueryset. Still, this is the correct behavior.

@spectras spectras added this to the v.0.5.0 milestone Jun 14, 2014
@spectras spectras self-assigned this Jun 14, 2014
spectras added a commit that referenced this pull request Jun 15, 2014
Replace custom metaclass with 'class_prepared' signal to prevent conflicts with other modules.
@spectras spectras merged commit beb1b29 into KristianOellegaard:master Jun 15, 2014
@spectras spectras deleted the feature/metaclass_removal branch June 15, 2014 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant