{"action":"created","issue":{"url":"https://api.github.com/repos/KristianOellegaard/django-hvad/issues/246","labels_url":"https://api.github.com/repos/KristianOellegaard/django-hvad/issues/246/labels{/name}","comments_url":"https://api.github.com/repos/KristianOellegaard/django-hvad/issues/246/comments","events_url":"https://api.github.com/repos/KristianOellegaard/django-hvad/issues/246/events","html_url":"https://github.com/KristianOellegaard/django-hvad/issues/246","id":85079007,"number":246,"title":"Better Integration with `django-mptt`","user":{"login":"barseghyanartur","id":4925587,"avatar_url":"https://avatars.githubusercontent.com/u/4925587?v=3","gravatar_id":"","url":"https://api.github.com/users/barseghyanartur","html_url":"https://github.com/barseghyanartur","followers_url":"https://api.github.com/users/barseghyanartur/followers","following_url":"https://api.github.com/users/barseghyanartur/following{/other_user}","gists_url":"https://api.github.com/users/barseghyanartur/gists{/gist_id}","starred_url":"https://api.github.com/users/barseghyanartur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barseghyanartur/subscriptions","organizations_url":"https://api.github.com/users/barseghyanartur/orgs","repos_url":"https://api.github.com/users/barseghyanartur/repos","events_url":"https://api.github.com/users/barseghyanartur/events{/privacy}","received_events_url":"https://api.github.com/users/barseghyanartur/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/KristianOellegaard/django-hvad/labels/new%20feature","name":"new feature","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-04T12:38:26Z","updated_at":"2015-12-13T00:18:12Z","closed_at":null,"body":"I have read this (http://django-hvad.readthedocs.org/en/latest/public/faq.html#how-do-i-use-hvad-with-mptt).\r\n\r\nI have models (see below). Admin works, ORM works.\r\n\r\n    from django.db import models\r\n    from django.utils.translation import ugettext_lazy as _\r\n\r\n    from mptt.models import MPTTModel, TreeForeignKey\r\n    from mptt.managers import TreeManager\r\n\r\n    from hvad.models import TranslatableModel, TranslatedFields\r\n    from hvad.manager import TranslationManager\r\n\r\n    class AbstractFacility(TranslatableModel):\r\n        translations = TranslatedFields(\r\n            name=models.CharField(_(\"Name\"), max_length=255),\r\n            slug=models.SlugField(_(\"Slug\"), max_length=255),\r\n         )\r\n\r\n        class Meta:\r\n            abstract = True\r\n\r\n        def __unicode__(self):\r\n            return self.safe_translation_getter('name', unicode(self.name))\r\n\r\n\r\n    class MPTTFacilityManager(TranslationManager, TreeManager):\r\n        use_for_related_fields = True\r\n\r\n\r\n    class AbstractMPTTFacility(MPTTModel, AbstractFacility):\r\n        parent = TreeForeignKey('self', null=True, blank=True,\r\n                                related_name='children', db_index=True)\r\n\r\n        objects = MPTTFacilityManager()\r\n\r\n        class Meta:\r\n            abstract = True\r\n\r\n\r\n    class MyModel(AbstractMPTTFacility):\r\n        translations = TranslatedFields()\r\n\r\n        class Meta:\r\n            verbose_name = _('My model')\r\n            verbose_name_plural = _('My models')\r\n\r\nI want now to use the those models in forms and make use of the `django-mptt` fields.\r\n\r\nhttps://django-mptt.github.io/django-mptt/forms.html#fields\r\n\r\nFor instance, the `TreeNodeMultipleChoiceField`.\r\n\r\n\r\n    from django import forms\r\n    from django.utils.translation import ugettext_lazy as _\r\n    from mptt.forms import TreeNodeMultipleChoiceField\r\n\r\n    class MyForm(forms.Form):\r\n        def __init__(self, *args, **kwargs):\r\n            super(MyForm, self).__init__(*args, **kwargs)\r\n            queryset = MyModel.objects.language('en')\r\n            self.fields['my_models'] = TreeNodeMultipleChoiceField(queryset, label=_(\"My models\"))\r\n\r\nWhen feeding the queryset to the `TreeNodeMultipleChoiceField`, I get errors.\r\n\r\nApplying this hack helps:\r\n\r\n    queryset.model._mptt_meta = MyModel._mptt_meta\r\n\r\nI'm not sure if `django-hvad` is supposed to go that far, but perhaps some copying some essential properties of the original model into translated model could be automatised or the workarounds documented.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/KristianOellegaard/django-hvad/issues/comments/164204096","html_url":"https://github.com/KristianOellegaard/django-hvad/issues/246#issuecomment-164204096","issue_url":"https://api.github.com/repos/KristianOellegaard/django-hvad/issues/246","id":164204096,"user":{"login":"spectras","id":5879675,"avatar_url":"https://avatars.githubusercontent.com/u/5879675?v=3","gravatar_id":"","url":"https://api.github.com/users/spectras","html_url":"https://github.com/spectras","followers_url":"https://api.github.com/users/spectras/followers","following_url":"https://api.github.com/users/spectras/following{/other_user}","gists_url":"https://api.github.com/users/spectras/gists{/gist_id}","starred_url":"https://api.github.com/users/spectras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spectras/subscriptions","organizations_url":"https://api.github.com/users/spectras/orgs","repos_url":"https://api.github.com/users/spectras/repos","events_url":"https://api.github.com/users/spectras/events{/privacy}","received_events_url":"https://api.github.com/users/spectras/received_events","type":"User","site_admin":false},"created_at":"2015-12-13T00:18:12Z","updated_at":"2015-12-13T00:18:12Z","body":"**Note:** there will be some time until hvad2 is released, but compatibility with third-party modules should be improved a lot, and make this kind of issues moot."}}