/usr/lib/python2.7/dist-packages/mptt/fields.py is in python-django-mptt 0.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | """
Model fields for working with trees.
"""
from __future__ import unicode_literals
__all__ = ('TreeForeignKey', 'TreeOneToOneField', 'TreeManyToManyField')
from django.db import models
from django.conf import settings
from mptt.forms import TreeNodeChoiceField, TreeNodeMultipleChoiceField
class TreeForeignKey(models.ForeignKey):
"""
Extends the foreign key, but uses mptt's ``TreeNodeChoiceField`` as
the default form field.
This is useful if you are creating models that need automatically
generated ModelForms to use the correct widgets.
"""
def formfield(self, **kwargs):
"""
Use MPTT's ``TreeNodeChoiceField``
"""
kwargs.setdefault('form_class', TreeNodeChoiceField)
return super(TreeForeignKey, self).formfield(**kwargs)
class TreeOneToOneField(models.OneToOneField):
def formfield(self, **kwargs):
kwargs.setdefault('form_class', TreeNodeChoiceField)
return super(TreeOneToOneField, self).formfield(**kwargs)
class TreeManyToManyField(models.ManyToManyField):
def formfield(self, **kwargs):
kwargs.setdefault('form_class', TreeNodeMultipleChoiceField)
return super(TreeManyToManyField, self).formfield(**kwargs)
# South integration
if 'south' in settings.INSTALLED_APPS: # pragma: no cover
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^mptt\.fields\.TreeForeignKey"])
add_introspection_rules([], ["^mptt\.fields\.TreeOneToOneField"])
add_introspection_rules([], ["^mptt\.fields\.TreeManyToManyField"])
|