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

Update mptt.rst #105

Closed
wants to merge 6 commits into from
Closed

Conversation

zhangguiyu
Copy link

minor edits to mptt example

@vdboor
Copy link
Contributor

vdboor commented Sep 30, 2015

Hi! Thanks for updating the docs!
Do you know which version of mptt is affected by this? I didn't see this happening before.

@zhangguiyu
Copy link
Author

Hi Vdboor,

I am using django-mptt==0.7.4 with django-parler==1.5

If I put MPTTModel in second position in my abstract model, i.e.,

class AbstractNode(AbstractModel, MPTTModel):

, I get errors like

Traceback (most recent call last):
  File "./manage.py", line 10, in 
    execute_from_command_line(sys.argv)
  File "/pythonenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/pythonenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/pythonenv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/pythonenv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/pythonenv/local/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/data/gits/irc/src/irc/models.py", line 18, in 
    from irc.abstract import *
  File "/data/gits/irc/src/irc/abstract.py", line 158, in 
    class AbstractNode(AbstractModel, MPTTModel):
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 189, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1778, in contribute_to_class
    super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 313, in contribute_to_class
    add_lazy_relation(cls, self, other, resolve_related_class)
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 86, in add_lazy_relation
    operation(field, model, cls)
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 312, in resolve_related_class
    field.do_related_class(model, cls)
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 355, in do_related_class
    self.set_attributes_from_rel()
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 345, in set_attributes_from_rel
    self.rel.set_field_name()
  File "/pythonenv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1432, in set_field_name
    self.field_name = self.field_name or self.to._meta.pk.name
AttributeError: 'NoneType' object has no attribute 'name'

However, if I put MPTTModel first, it works, i.e.,

class AbstractNode(MPTTModel, AbstractModel):

P.S. I am following the same approach as django-categories-i18n, which also listed MPTTModel first:

#categories_i18n/abstract.py
class AbstractCategory(MPTTModel, TranslatableModel):

@vdboor
Copy link
Contributor

vdboor commented Oct 1, 2015

Good to know! If you can update the pull request, I'll merge it!

Removed fieldsets from CategoryAdmin in the example.
cosmetics
Added switch for MPTTQuerySet or TreeQuerySet
@zhangguiyu
Copy link
Author

I have updated the pull request with a switch that checks for MPTT version. Should work now with Travis CI with various MPTT versions.

vdboor added a commit that referenced this pull request Oct 5, 2015
Based on the hints from PR #105 by @zhangguiyu
@vdboor
Copy link
Contributor

vdboor commented Oct 5, 2015

I've merged your changes in cb12319!
The MPTTQuerySet code had to be removed, there is nu such class in the django-mptt git history.

Thanks for the work, and bringing the issues of the docs to our attention!

@vdboor vdboor closed this Oct 5, 2015
@zhangguiyu
Copy link
Author

Thanks!

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.

None yet

2 participants