MyModel has a mptt’s TreeForeignKey field category. In the admin of MyModel, how can I disable some options in the Select widget of this category field?
Thanks you
class Category(MPTTModel):
parent = TreeForeignKey('self', blank=True, null=True, related_name='children')
nom = models.CharField(max_length=100)
class MyModel(models.Model):
category = TreeForeignKey(Category)
# more fields
I had to overwrite MyModelAdminForm and use a
forms.ChoiceFieldfield with a SelectWithDisabled widget for thecategoryfield. In my case I only wanted the leaves of the tree to be selectable.