Django - It is possible to use Haystack with custom SQL directly - django

I'm in the process of choosing a Framework for a new project. I have basically the database schema developed(I have this schema running in other PHP webapps already).
In this project I will need to basically search the database schema with Solr. The database schema is a little bit complex to define models in Django, so I think the only option I have is to execute SQL directly... my doubt is about Haystack/Solr... It is possible to query Haystack/Solr when I have no Django Models defined?
PS: I'm new to Django, I have never userd Haystack.

Haystack is pretty tightly coupled to the Django ORM. If you're not using Django models, I don't think Haystack is suitable. I've only used Haystack briefly, so I might wrong.
From the Haystack docs:
When should I not be using Haystack?
Non-Model-based data. If you just want to index random data (flat files, alternate sources, etc.), Haystack isn’t a good solution. Haystack is very Model-based and doesn’t work well outside of that use case.

I never used haystack, but you can always perform raw sql queries.
Have a look on documentation:
https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly

Related

How to setup rethinkdb with django?

I have followed various posts and tutorials but couldn't find anything that is relevant. I found a ORM for rethinkdb "https://github.com/dparlevliet/rwrapper" but don't know how to use it?
I am new to to django and python.
It depends on what you want to do.
There is no way to simple replacement of Django's ORM with RethinkDB now. However, working with RethinkDB driver is simple enough, and similar to how you would use Django ORM.
The nearest thing is indeed rwrapper, you can try starting with this tutorial.
If you don't need to use Model classes, then you just need to find a place to connect to database (or use some sort of Singleton or Factory to connect to the database), and then just import rethinkdb as r and r.connect() and then just write queries with ReQL.
If you need realtime data, then Django is not suitable for that at all. You can consider mixing Django with Tornado
Django doesn't support RethinkDB at the moment and I don't think there's any plan for it as well.
Django developers don't add new stuff to the code base just because it's something new and might be cool. It should be really well mature and a high needs for it. So, I don't think you'll be hearing anything about RethinkDB from Django devs anytime soon.
This project might be something interesting:
https://github.com/thejsj/django-and-rethinkdb
In order to use any database with Django, the adapter should completely be a Django DB Backend in order to work with:
Models
Admin
Forms
Various Class Based Forms
Session
Auth
etc...
In others words, as long as the db backend doesn't support all the django database operations is not something that you wanna use.

What functionality is lost when using django with mongodb?

I am evaluating whether I want to use mongoDB with django for my next project. What I am not sure about, though, is what functionality (ORM, admin, forms, etc.) I loose when I use a DB backend that is not officially supported.
I consider using the mongodb-engine.
So, you have Django-mongoadmin and Django-mongonaut for django-admin stuff. Also
Django-mongodbforms for model forms. MongoEngine as ORM. But this modules are pretty raw and unstable so use it with wariness.

Django-nonrel vs Django-mongodb vs Mongokit vs pymongo native

Working on a Django project that requires a NoSQL store and I believe I've settled on Mongo. I've seen a lot of topics that talk about Mongo and Django, but none that mentioned Django-nonrel, and I can't see why it might have been disqualified, but I have no experience with any of them.
Ideally, I'd like to preserve the SQL store for the simple things, user auth, groups, etc., and use Mongo for the bigger data.
I'd also like to have my Mongo-stored objects as classes, in a Django-ORM style, so that I can have a similar 'feel', but that isn't critical.
Lastly, do any of the above allow me to use Django's multi-database support for anything, or are all my mongo queries effectively 'out of band' from the Django ORM?
If there are any other factors I'm missing that might be important, feel free to clue me in. I know little in this arena.
Django-nonrel is the way to go for Django on MongoDB. There's django-mongodb.org, but that's just built on top of Django-nonrel. There's quite a bit of mongodb activity going on the django-nonrel mailing list.
Storing your mongo classes as Django ORM objects works fine, that's the whole point.
I haven't tried using the multi-database support along with SQL. I haven't seen many people use it like that, and I suspect it most likely does not work. There's some work on moving django-nonrel to be officially part of Django 1.4, I suspect it'll work after that's complete.
Using django-nonrel for auth works ok. The main problem is many-to-many relations. The auth module uses that for per user object permissions - that doesn't work. If you don't need that, you could probably get away without using the SQL at all.
Adding onto dragonx answer. The issue with django-nonrel is that the auth module doesn't work.
You can perform many-to-mamy joins using $lookup operator. djongo does automatically for you. It translates SQL syntax into mongodb aggregation queries and populates the object model, like other SQL drivers.
The auth module works fine on djongo

Django: Haystack or ORM

For a project I implemented Haystack but now I was wondering what the pros and cons are of using Haystack over the ORM. For my project I need to find books by their title and isbn. I guess Haystack is more useful if you have to do full text searches or am I missing something?
Haystack is certainly better for full text search, and also provides a bunch of other benefits that you won't get using the ORM. Here are some from the Haystack site:
Spelling suggestions
Faceting
More like this
Highlighting
Search term boosting
Besides that, you should use Haystack over the ORM if you expect a high volume of searches, since you'll offload all that work from the DB (which should be focused on writing and retrieving your data).
http://haystacksearch.org/
The main advantage to use haystack over the ORM is performance. LIKE requests are just going to kill you database if you have 100 concurrent users searching. If you have MYSQL of course you can still use its full text capability, but it will still be slower than Xapian or Solr.
Plus you will have additional features such as fuzzy searching that user loves a lot.
It does comes with the extra work of setting up solr and maintaining it, so:
if your website is going to be small forever, like for small company intranet, don't bother and user ORM.
if you plan for the big bad Web, go Haystack.
And not forget to mention that doing a basic haystack setup isn't really much more work than doing a search view using Django's ORM.
Haystack is a module that enables easier search integrations for your django application
you can create something similiar to a ModelForm, called ModelIndex, in this new class you will be able to declare the searchable fields of your models and other settings
It has little to do with Django ORM (the orm is used to comunicate with your databases)
of course you can have the orm query your db models with the search pattern specified, but Haystack is a better choice for setting up a search engine easily on your website, so... if you have to enable complex searches on your site, just go with Haystack

Does django create a clean database?

I am building a web interface for a database at my school. The database will hold our school's versions of academic standards.
When you build a site using django, does it create a clean database? For example, wysiwyg website builders like dreamweaver create ugly html and css code on the backend. I would hate to see a similar degree of auto-generated cruft in my database.
Should I create the database myself and then build a django site to access the database, or go ahead and let django create the database?
Under any simple to moderately complex application, Django will do a fine job creating the database for you. I've yet to run into any issues with what it's made.
I would suggest that you use South to handle your table migrations. And use virtualenv and pip to set up and maintain your Django environment.
You can use the sqlall predicate of manage.py to see the exact SQL that will be executed in order to generate the database.
Obviously django needs database tables for its basic functionality (contrib.apps).
Sure, you don't have to use them, but generally you want to use a least contrib.auth and some other bundled apps:
Each of these applications makes use
of at least one database table,
though, so we need to create the
tables in the database before we can
use them.
I any case you can't and shouldn't compare it to ugly html code generated by dreamweaver or word.
On a more abstract level:
One of key concepts of a web framework (following the mvc pattern) is that you define models which are "translated" (mapped) by the framework into database tables.
A model is the single, definitive
source of data about your data. It
contains the essential fields and
behaviors of the data you’re storing.
Generally, each model maps to a single
database table.
If you want to create the whole database scheme by hand you totally missed the point of using a web framework. In most cases you simply don't need to write sql manually. You define your classes and then you can query your objects using the builtin orm.