| Issue 20: | mptt after qs-refactor merged into trunk (SOLVED) | |
| 3 people starred this issue and may be notified of changes. | Back to list |
Mppt works now incorrect with child of models that was registered.
As far i know mptt does not receive pre_* signals.
So i have modified mptt for dynamic determination of _meta. (When child
model saves, mptt must use _meta of her parent if parent was already
registered).
My modifications:
__init__.py
- parent_model attr added to register()
- logic of register() a bit changed
- if model has already registered parent, i add "mptt_parent_meta"
attribute
utils.py
- new method get_actual_opts()
managers.py
- lines "opts = self.model._meta" changed to
"opts = get_actual_opts(self.model)"
signals.py
- lines "opts = instance._meta" changed to
"opts = get_actual_opts(instance)"
It works for me, but you must manually create fields for parent model.
lft = models.PositiveIntegerField(db_index=True, editable=False)
rght = models.PositiveIntegerField(db_index=True, editable=False)
tree_id = models.PositiveIntegerField(db_index=True, editable=False)
level = models.PositiveIntegerField(db_index=True, editable=False)
So its child can use it.
Hope its helps to make project better. If you have some questions, please
feel free to contact me by email.
Alex Dobretsov, my email krylatij@gmail.com
May 5, 2008
attached Alex Dobretsov's patch as a .diff for convenience.
Jan 27, 2009
Is there a version of this in existence that will work with Django 1.0.1+? Many thanks!
Sep 3, 2010
Fixed in the latest stable release.
Status:
Fixed
|
Forget to say, if we have 2 models use syntax like class A(models.Model): lft = models.PositiveIntegerField(db_index=True, editable=False) rght = models.PositiveIntegerField(db_index=True, editable=False) tree_id = models.PositiveIntegerField(db_index=True, editable=False) level = models.PositiveIntegerField(db_index=True, editable=False) .... class B(A): .... mptt.register(A) mptt.register(B, parent_model=A)