MPTTModel as target of ManyToManyField and Admin-Widget

370 views
Skip to first unread message

grandfatha

unread,
Nov 25, 2011, 5:48:56 AM11/25/11
to django-mptt-dev
Hi,

thank you for your awesome work on django-mptt. I got it up and
running very quickly. My model looks like this:

class Technology(MPTTModel):
name = models.CharField(max_length=150, blank=False)
parent = TreeForeignKey('self', null=True, blank=True,
related_name='children')

class MPTTMeta:
order_insertion_by = ['name']

class Organisation(models.Model):
technologies = models.ManyToManyField(Technology, blank=True)


Basically I want to store a bunch of organisations which are capable
of some technologies. The technologies itself can be arranged in a
taxonomy.


To allow easy entering of data, I added the following to my admin.py:

class OrganisationAdmin(admin.ModelAdmin):
filter_horizontal = ['technologies']

admin.site.register(Organisation, OrganisationAdmin)


My question is:
Is there a way to change the ManyToMany FormWidget to be aware of the
taxonomy of technologies? Can they be displayed with an indentation
inside the regular admin-m2m-widget?

Thank you for your guidance.

Craig de Stigter

unread,
Nov 27, 2011, 5:39:26 PM11/27/11
to django-...@googlegroups.com
Nope, this isn't something django-mptt does yet, although it'd be a useful addition.

It looks like the admin's SelectBox widget javascript doesn't enforce any ordering. When moving items between the select widgets, it always appends them to the end of the list, rather than keeping existing ordering. So step 1 would be to fix that in admin/media/js/SelectBox.js. I'm guessing the django devs might consider accepting that into upstream, since lots of models have a 'natural' ordering and it's a shame to lose that in the widget.

As for adding indentation, how hard can it be ;)

Happy to accept a pull request... Cheers
Craig
Reply all
Reply to author
Forward
0 new messages