Django admin site with mongodb

2019-05-14 14:13发布

问题:

I am using django with mongodb through django-mongodb. I was able to set up the django admin site (through the fixes on the troubleshooting page), now when I use the admin site I am able to view all of the top-level fields, but (somewhat as expected) the embedded objects and lists are not able to be viewed, they just show up as a print would show them, "List Object" for example.

Is there any way to use the admin interface to view the sub-models etc...?

If there is no convenient third-party way, how would I go about supporting this behavior myself?

If there is no simple way to support this myself, is there a phpmyadmin type of thing for mongo that I can use in conjunction with django-mongodb (This could just be something that sits on top of mongodb not necessarily using python/django)?

*Note: I have been using the word 'view' in reference to my interaction with the model, my first preference is to be able to view and not edit, however if there is editing capability out there, that might be better, depending on how complex the modifications will be.

回答1:

I have actually been doing the same project lately. The admin site doesnt really know how to represent the non-relational style elements that are present in a mongodb document, so you would have to define custom field/widgets. Refer to this part of the documentation which explains how to extend your ModelAdmin to specify overrides. https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#modeladmin-objects

For list types for instance, django has no way to know what type of values the list contains and how to represent them.

As for a visual mongodb manager, not sure what OS you are on, but Im on OSX and I love this one: http://mongohub.todayclose.com/

Otherwise, here is a list of other management options: http://www.mongodb.org/display/DOCS/Admin+UIs

Take your pick for either an OS native or web based.