django-mptt ImportError

2019-07-15 12:06发布

问题:

I have installed django-mptt and have followed the documentation regarding setting up a Django model for MPTT

However, I am getting the following ImportError:

 from mptt.models import MPTTModel, TreeForeignKey
 ImportError: cannot import name TreeForeignKey

Can anyone help?

Any advice appreciated.

Thanks.

回答1:

TreeForeignKey is a class defined in the file fields.py. It looks like this file was just recently added to the code base for v0.5.pre.

If you are using version 0.4.2 or older, this file and class don't exist. I'm not sure how this package is intended to be used without this class, since the documentation only applies to the latest version of the code (v0.5.pre).

Good Luck!



标签: django-mptt