MongoEngine / django-mongoengine

django mongoengine integration
Other
750 stars 206 forks source link

Support for basic mongoengine integration with Django #22

Open foxx opened 10 years ago

foxx commented 10 years ago

Not sure if this helps but, I've made a simple django-mongoengine which can support handling Mongoengine connections via the Django connection manager, and adds setup/teardown unit test support when using mongo databases.

There is some nasty monkeypatching to make this work, but so far it seems to work pretty well out of the box. Although it doesn't add support for admin panels or anything, it works great for those that just want to use a mongodb connection in Django without any fuss.

Happy to do a better PR if you feel it's worthy enough for inclusion.

garrypolley commented 10 years ago

Thanks for the suggestion @foxx

Have you looked into making https://github.com/MongoEngine/django-mongoengine/tree/master better support Django + Mongo?

foxx commented 10 years ago

I'd had a look a few months ago, but wasn't keen on the approach used, and ended up making my own lightweight version as linked.

For example, handling setup/teardown of unittest data is done inside MongoTestCase, but this isn't the best way of doing things. It requires the user to inherit their unit test directly from that class, which is an unclean pattern. It would be slightly better if it worked as a mix-in, which would most likely need to contain some nasty MRO magic, but even then it still wouldn't be a great approach, for much the same reasons.

This also requires you to use MONGODB_DATABASES rather than just specifying the database inside DATABASES with a mongoengine engine string, which again feels unclean.

Both of these features could probably be merged without too much problem, although it would require a lot of testing as monkey patching could cause some weird edge cases. These changes would, naturally, be backwards incompatible for most people too.

I'm not sure if it would break the other elements such as forms/admin, I personally have no use for them as all my use cases for Mongo involve multi layer documents. The forms abstraction for Django is just not designed well for deep document resources, even with the support of EmbeddedFormField (in my own opinion), but this is a design fault with Django, not django-mongoengine.

argoyal commented 9 years ago

@foxx : We can use https://github.com/hspandher/django-test-addons which provides the setup and teardown functionality after run of each test case.

I also have concern here, How are we running the test cases here? I am trying to use pytest, will it be usable?

qwiglydee commented 9 years ago

So far, @foxx killed his repository. Is the functionality merged into this project?

foxx commented 9 years ago

I have since stopped using Django, as I now consider it broken by design. The repo itself was killed because of backwards incompatible changes after the last Django release. I can dig out the code from archive if needed, but it's probably better to do it again from scratch.

qwiglydee commented 9 years ago

@foxx your blog post "42 awesome tools for programmers" does not mention django in section "Things to avoid". Wouldn't you write something about why django is broken and what do you use instead?

foxx commented 9 years ago

@qwiglydee I've got something coming out soon that tackles this very topic, stay tuned :)