How read collections of mongodb on django environment - django

I have this 2 collection on mongoDB
airports
routes
I was searching how do that, I found djongo. After reading I understood the following.
I must make models that matching those data, then only use queries.
There are models only with few fields. Then I could use this methods e.g.
Airports.objects.filter(name_airports__startswith='Goro')
am I right?
If anyone can guide me to right way , I'll be very grateful. If you have
an example on the web, please share that with us, thanks in advance.

Related

how to implement django haystack elasticsearch static webpages

I have a tutorial site [say JavaScript tutorial] with multiple webpages. I want to implement a search functionality for this site so that i can search for keywords and filter links [say query=callback. So filter links/pages that i have this keyword]
I have already implemented haystack+woosh this can index all the models that i have in my models.py in Django. I want to implement indexing for the webpages so that i can search through them. I know elasticsearch [i will implement models in elasticsearch as well instead of woosh. This i know how to do] can be used for this. I was looking for specific example for how to index STATIC PAGES in a site to search through them. I have gone through some tutorial and git code but don't have a clear understanding of how to implement this. Can anyone please provide links/ tutorials on how to implement elasticsearch in django TO INDEX WEBPAGES.
Thanks,
there is an extension for haystack that does exactly this: https://github.com/trapeze/haystack-static-pages
It is pretty old and no longer maintained, but you might get it to work with a little extra effort. I think this is a good solution.
Another solution would be to include all text in a simple Content Management System like Wagtail or Mezzanine. In the most basic implementation, you can refactor your static files to templates and just replace the text with placeholders. Wagtail works nicely with haystack.
I hope this helps,
Felix

Django models architecture for full-text search in PostgreSQL

I'm building a web-site for a social interaction on a particular topic, based on threads, think of gmail, only public. There will also be some static info in vocabularies, as well as blog, how-tos, knowledge base, etc. It is django+postgres.
One of the most important requirements is a full-text search over all information, regardless of the type of a model. If the exact search phrase appears in the blog, and its twisted sister in messages, than a snippet from the blog entry should appear first in the search results and be followed by a snippet from the message. So, i need a table with all the texts indexed, and the links to _any_other_table_ in the db.
My first idea is to create a separate model with "loose reference", e.g.:
class Content(models.Model):
obj_id= CharField() # An id of the object of a given model.
model= CharField(choices=("Message", "BlogEntry", "HowTo", "EntityProfile",))
content_type= CharField(choices=("subject", "body", "description", "tags",))
body= TextField()
But it feels kind of wrong... This promises an unnecessary hassle around integrity of references when creating and re-linking instances.
So, the question is - is there any elegant solution that django would provide? What might be the most efficient architecture to solve the problem?
I am not asking for a direct answer, but rather a hint.
Thanks in advance!
I've had a lot of success working with this snippet, which uses PostgreSQL's tsearch2. I've tweaked it for various different purposes in various different ways, but basically it works very well, and is very easy to implement.
Thanks a lot for the hints!
while contenttypes is an ideal for this kind of task, it is really tempting to be DB independent
from what i've read so far, Solr is a reliable search engine, but i think, i'll go and try ElasticSearch via Haystack
thanks again!

Single model for storing django application-wide options

I have a set of top-level configuration data fields that I want to be able to set within django admin for each deployment of my django app. I only want one set of these.
Example fields: site_logo, contact_person, address, facebook_url, twitter_url
The problem is that Django Admin is geared towards tables (lists) of models, so its not a good fit for this type of singular configuration model. I really only want one of these models to exist for the whole site, and to be able to click into it from admin and edit the various fields.
It seems i've come across a 3rd party app in the past to accomplish this but can't find it anywhere. Part of the problem is I'm finding it difficult to find the right words to google. Any ideas?
It looks like django-values will do what you're looking for.
Other possible contenders:
http://github.com/sciyoshi/django-dbsettings (doesn't look maintained)
http://github.com/jqb/django-settings
Have a look at django-livesettings it sounds like it might fit.
Not that i have used it, but i have heard good things about django-constance.
And there are even some more options listed in the Configuration-Grid on Django Packages.

Django search for static parts of the site

I am planning to use Django-Haystack to add a search component to my site. This will take care of the data I have in my models.py. I however also want data which is not in a model, but part of templates to be searchable. How can I get this.
There is a django app called haystack-static-pages that should help here. It's not been updated for a while so I doubt it will work with haystack 2.0, but I hope this might be of some help to you:
https://github.com/trapeze/haystack-static-pages

Django sortable many to many relationship?

I want to set up a many to many relationship between two models, Gallery and Image. I would like to be able to sort them in the site admin in order to change the order the images appear in a gallery on the frontend.
Is there anything built into Django which will help me do this?
I don't want to reinvent the wheel!
Any advice appreciated.
Thanks.
Nothing built-in, no. There's order_with_respect_to, but that's for ForeignKeys and doesn't really expose any functionality in the admin.
A quick Google reveals django-sortedm2m, which I haven't used but is by Gregor Müllegger, who's contributed a fair amount to Django, so is likely to be reliable.