django-tables2 - show all per page - django

Good afternoon,
im using Django-tables2, I know in the query string I can set per_page and have used the below template tag to create some urls
{% querystring "per_page"=20 %}
however is it possible to show all items per page via a url? ive tried using -1 and 0 but it does not work, the only thing I can think to is put a ridiculous number like a billon which works, but I dont think thats a clean implementation?
Thanks

Related

How to show django filter form elements seperately

I am new to django and using the material online I was able to build a filtering form using django-filter. I am able to show the filter on the html page using a format as below:
{{filtergroup.form}}
This does show the filter correctly and worked well on the page however I wanted to check if there is a way to show individual elements / filters in the form separately so that I can arrange the filters and format easily. Please advise.
Thank you!
If you have a field, say, author, you can access it like this :
{{ filter.form.author }}

How do I access my query when using Haystack/Elasticsearch?

I originally followed this tutorial (https://django-haystack.readthedocs.org/en/latest/tutorial.html), and have so far been able to highlight my query within my returned results. However, I want to highlight this same query when visiting the next page that I load with a separate template. Is there any way to save/access this query so that I can highlight the same results within this other template?
Whenever I try and include a statement like this, I get an error, which I'm thinking is because I'm not trying to access the query properly.
{% highlight section.body with query html_tag "span" css_class "highlighted" %}
You have to send to the next page, the information that you use to highlight the results in the first page. You can use the request.session to store the data and call it in the next page, or you can send the sqs by the url to the next page.
If you want to know how to manage the search query set, and how to edit that kind of stuff, I recommend you to read the views.py forms.py and the elasticsearch_backend in the haystack folder at: "/usr/local/lib/python2.7/dist-packages/haystack"
This is the url for the documentation of Django Session: Django Session
This is the url for the documentation to pass parameters trhough url: URL dispatcher

Use custom tags in database content

I am creating a custom CMS, with the purpose to learn more about Django.
What I'm trying to achieve is the use of tags in database content. I have a dynamic amount of placeholders attached to a page. Each placeholder can contain tags, like "current_time".
In the template I'm going to output the placeholder like this:
{% placeholder sidebar %}
And in the admin I want to do this:
This is the sidebar, the time is {% current_time "%Y-%m-%d %I:%M %p" %}
Well, the outputting is working, but the "current_time" tag isn't parsed. It's displayed as plain text. I have been looking for hours for a solution; tried regular tags, inclusion tags, simple tags, numerous snippets. But as you might guess, I still haven't found a solution.
Can anyone point me in the right direction?
Process the text as a template.

Putting links in list_detail.object_list to list_detail.object_detail

I've started using Django and am going right to generic views. Great architecture! Well, the documents are great, but for the absolute beginner it is a bit like unix docs, where they make the most sense when you already know what you're doing. I've looked about and cannot find this specifically, which is, how do you set up an object_list template so that you can click on an entry in the rendered screen and get the object_detail?
The following is working. The reason I'm asking is to see if I am taking a reasonable route or is there some better, more Djangoish way to do this?
I've got a model which has a unicode defined so that I can identify my database entries in a human readable form. I want to click on a link in the object_list generated page to get to the object_detail page. I understand that a good way to do this is to create a system where the url for the detail looks like http://www.example.com/xxx/5/ which would call up the detail page for row 5 in the database. So, I just came up with the following, and my question is am I on the right track?
I made a template page for the list view that contains the following:
<ul>
{% for aninpatient in object_list %}
<li><a href='/inpatient-detail/{{ aninpatient.id }}/'>{{ aninpatient }}</a></li>
{% endfor %}
</ul>
Here, object_list comes from the list_detail.object_list generic view. The for loop steps through the object list object_list. In each line I create an anchor in html that references the desired href, "/inpatient-detail/nn/", where nn is the id field of each of the rows in the database table. The displayed link is the unicode string which is therefore a clickable link. I've set up templates and this works just fine.
So, am I going in the right direction? It looks like it will be straightforward to extend this to be able to put edit and delete links in the template as well.
Is there a generic view that takes advantage of the model to create the detail page? I used ModelForm helper from django.forms to make the form object, which was great for creating the input form (with automatic validation! wow that was cool!), so is there something like that for creating the detail view page?
Steve
If you're on django < 1.3 then what you are doing is basically perfect. Those generic views are quite good for quickly creating pages. If you're on django 1.3 you'll want to use the class based generic views. Once you get a handle on those they are are crazy good.
Only note I have is that you should use {% url %} tags in your templates instead of hardcoding urls. In your urls.conf file(s) define named urls like:
url('inpatient-detail/(?P<inpatient_id>\d+)/$', 'your_view', name='inpatient_detail')
and in your template (for django < 1.3):
...
In 1.3 a new url tag is available that improves life even more.

django-threadedcomments to return number of comments excluding replies

I'm using
{% get_comment_count for OBJECT as CONTEXT_VAR %}:
to get the number of comments that an object has. The issue with this is that you can't limit it by depth. I want to be able to get for example the number of comments a specific object has had excluding the replies made to the comments it self.
Any ideas on how to achieve this?
Use your own templatetag or count them in the view and pass it to the template.