Accessing the model instance from within ModelAdmin?

Untested !
TODO: test this

    def get_object(self, request, model):
        object_id = request.META['PATH_INFO'].strip('/').split('/')[-1]
        # ?? object_id = resolve(request.path).args[0]
        try:
            object_id = int(object_id)
        except ValueError:
            return None
        return model.objects.get(pk=object_id)

Credits: http://stackoverflow.com/questions/949268/django-accessing-the-model-instance-from-within-modeladmin

Allow Bi-Directional ManyToMany in Django Admin

class Node(BaseEasyTree, PaintdbBaseModel):
    ...                
    pigments = models.ManyToManyField('Pigment', blank=True, verbose_name=_(u'Related pigments') )
                
class Pigment(PaintdbBaseModel):
    ...
    # Allow Bi-Directional ManyToMany in Admin as suggested here: https://code.djangoproject.com/ticket/897#comment:28
    #TODO: check South behaviour; probably a fake migration is needed
    nodes = models.ManyToManyField(Node, through=Node.pigments.through, blank=True, verbose_name=_(u'Related products'), related_name='node_pigments', )
 
class PigmentAdmin(PaintdbBaseModelAdmin):
    ...
    filter_horizontal = ('nodes',)
    ...
    fieldsets = (
        ...
        (_('Relations'), {'fields': ('nodes', )}),
        ...
    ...
    # eventually filter related elements
    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "nodes":
            kwargs["queryset"] = Node.objects.for_user(request)
        return super(PigmentAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)