django - the best way to combine pagination with filtering and request.POST - like stackoverflow - ajax? - django

I want to combine pagination with filtering. Since I have a lot of filters I do not want to send them per GET request, since the URLs get really ugly.
Since django pagination uses GET request to pass the page parameters, I do not know how I can combine these two approaches.
Any idea?
Great add-on would be: How can I combine this approach with table sort? :-)
Edit:
Actually it should work like the pagination of stackoverflow - user questions. If a user clicks on a page number one is shown the correct page, without showing the get parameters in the url.
This is the url called.
https://stackoverflow.com/api/userquestions.html?page=2&pagesize=10&userId=237690&sort=Recent
But the url shown in the browser is neat and short.
Seems to be ajax. Anybody an idea how to implement this? :)
If the URL is not shown in the browser`s address bar, I do not care about whether it is beautiful or not.
Edit: The solution:
Make an ajax update with all filter parameters passed to the view. This should help you get started with implementing ajax for your site: link
Thus the GET parameters never show up in the address bar.

have you checked the paginate application for django?
it may help you a lot, use it all the time :D
http://code.google.com/p/django-pagination/

Have you considered django-tables2? It gives you django-admin style tables without you having to write the logic yourself.

maybe you can use the urs, something like:
http://oursite.com/something/filter1/filter2/3/
the doc -> http://docs.djangoproject.com/en/1.1/topics/http/urls/

I figured out two solutions:
Instead of using just hyperlinks use it inside a POST form, i dont have any example now but i remember have used that for REST functions in Ruby on rails
Save the query info in a session.
Hope this help.

Related

Django forms: submission with mixed requests (get and post)

for seo related reason in my project i have to trap certain search parameters within the url for the "beautiful url" thing.
The advanced search is composed by 7 parameters, 3 of which are location-related and are the ones interesting our seo consultant.
So, now i'm a bit confused. It's been a while since i started using django professionally, but never had to face an issue like this. Basically, the final url structure must be something like this:
/Italy/Lombardy/Milan/?price=100&miles=10&last_posted=2
and my urls.py is
'/(?P<country>\w+)/(?P<zone>\w+)/(?P<city>\w+)/$', SearchView.as_view()
now, what i'm not sure about is how should i specify my request in the form method to be able to use that exact url schema? POST or GET? And how can i compose the url for the "action" attribute dynamically while the user types? Is this even the correct solution? I'm really confused about it, any help would be really appreciated! Thanks!
you will have to change the action field of the form using script, yes. and set the method to GET, and include in the form only the fields appearing in the query string.

Django API: how to construct URLs, and handle queries?

Forgive this newbie (and possibly subjective - I don't know) question.
I want to add a REST API to my site. For example, I have a URL that is /post/ that shows all posts, and I'd like to give users a way to get all posts back in JSON.
Is is better to:
define a new API URL structure (e.g. /api/rest/post/ to return all posts in JSON)
use the existing URL structure, and allow users simply to append /json/ on the end of each URL to get JSON objects back? (e.g. /post/json/ to return all posts in JSON)
If the latter, then is there a standard way to implement it, in terms of views? Should I simply add an optional json parameter to all my views?
Thank you for your advice.
Take a look at Piston, which is a Django plugin to handle REST APIs.
Listen to the previous commenter's advise. But in particular that's probably better to use new API URL structure (/api/rest/post/ as you've said). Separating totally different kinds of functionality is always good for your project. In other words, you can place your API documentation at /api/docs/, and it will look natural. If you use same URL structure, it will be not so obvious where to place your docs.
The answer is of course also subjective.

Django , Break Page like wordpress Break Page?

there is any way to make a Break Page with django for using with large articles?
thanks
Run your content through a template filter, similar to Linebreaks (as an example)
So, you could make a "parsemore" filter, or something like that.
Documentation for making filters can be found here: http://docs.djangoproject.com/en/1.1/howto/custom-template-tags/

Easy way to submit POST data from a hyperlink in Django? Equivalent of Rails' `button_to`?

Is there a quick way to submit (pre-defined) POST data from a hyperlink in a Django template? I've got an 'add this to my favourites' link on page. I'm currently doing this with a GET request, which obviously breaks all kinds of rules.
I could manually build a form and have the link submit it with Javascript. I'm looking for an automatic way to do the same thing, essentially the equivalent of Rails' button_to.
Not that I can find. Sounds like a good candidate for a template tag and sharing.

example using django-proxy?

Have you used django-proxy? Can you give me an example of when it would be a good idea to use it? Thanks.
The blog engine Mingus, which I use for my blog, includes django-proxy to allow you to post items of different content types - blog posts, quotes, etc - but have them all appear on the index page in a similar format.
In response to Hank's comment, this is a completely different thing to 'proxy models' - those are for subclassing a model without creating a new table, in order to change some specific functionality rather than any actual fields. This has nothing to do with what django-proxy does.