<marginally-informed opinion> I do not believe that django-mptt supports this. </marginally-informed opinion> If what you trying to do is mimic a filesystem, this would work:
class Folder(MPTTModel):
parent = TreeForeignkey('self', related_name='children', null=True, blank=True)
name = models.CharField()
type = models.CharField()
class File(models.Model):
folder = TreeForeingKey(Folder)
name = models.CharField()
encoding = models.CharField()
But it obviously introduces the need for a recursive function to get both the folders children and folders files in a view.
To avoid any recursion, you could do something like this:
class FileObject(MPTTModel):
parent = TreeForeignkey('self', related_name='children', null=True, blank=True)
name = models.CharField()
type = models.CharField(Choices=(('file', 'file'), ('folder', 'folder'))
encoding = models.CharField(blank=True, null=True)
Though this will require some bit-fiddlying in the FileObject.Save to ensure only FileObjects with a type='file' get an encoding and that all of them do so and to make sure that no files get any children.
To my limited knowledge, with django-mptt (I know nothing of django-polymorphic-tree), it will come down to the least bad option: recursion or application enforce DB integrity. Personally, if I had to do this with django-mptt, I'd opt for recursion.
Just my $0.02
-richard