How to implement previous- and next-links in the object-detail-view of a search-result? - django

I am almost done with my first production-ready django-project. I got one big problem left:
I got an article-search-view that renders a list of found articles. Pagination is working just fine for the resultlist. When I click on the article-title the object-detail-page opens. What I want: previous- and next-result-links on the object-detail-page.
I tried several approaches to similar problems but didn't find a working solution. If I try to use a paginator with only one article (for the object-detail-page) I need to know that paginator-index in the resultlist. But how?
Even the .get_next(previous)_by_foo-Method is not really usable in this scenario AFAICT. Or am I missing something obvious here? Thanks for any help in advance!

Paginator from django works with lists. A way of searching indexes in lists it's like that:
['aaa', 'bbb', 'ccc'].index('bbb') # result: 1
or so like this:
model = object()
[object(), object(), model].index(model) # result: 2
Hope that gives you a hint on how you find paginator-index on your list.

If you want to get a link, at object-details-page, to next item from search-result, you must get next item from the search-result. To get a next item you need to perform the same search query which was executed in search-page and apply some extra filters to get only the next item from that list. But here you have a problem: you only have object-id in object-details page, you don't have the search-term. Without search-term you won't be able to create the search-query. That means you need to get search-term somehow. How do you get that search-term? You need to pass it from the search-result-page somehow. You can save the search-term in session/cookie, or, maybe better: you can pass it via a GET parameter to object-details page. Now when you search-term in object-display page, you can perform a search-query, and from that query you can select the next and the previous objects.
I think now you should be able to implement that. If not you could show some of your code of object-details view, maybe someone will write some code for you.

you could use this
next »
« previous

Related

How to go back multiple pages in ionic 3

I have the page flow like below:
A->B->C->D
Somehow I will do a function in page"D", after it need to go back page"B".
How can I achieve that?
Using .pop() just can go back one page.
Using .push(B) is also not the solution, because the flow will become:
A->B->C->D->B
The solution I want is:
A->B
Anyone know how to achieve it? Thanks a lot.
this.navCtrl.popTo(this.navCtrl.getByIndex(this.navCtrl.length()-(N+1)));
Where N is the number of pages that you want to go back.
So if you want to go back 2 pages N=2
Try Using the popTo() method by giving the index of page in a parameter like below:
nav.popTo( this.navCtrl.getByIndex(1))

Query not responding to order_by

I'm trying to order_by a query but i cannot seem to accomplish it, any help would be appreciated
users = User.objects.filter(Q(groups__name=group)).distinct()
This is the starting query i have tried many ways to make this work with the order_by method. But cant seem to get it working i am trying to order the query by the first_name in descending order.
.order_by('-first_name'.desc())
Something like this?
I get an error 'str' object has no attribute 'desc'
I have tried to look this up but cant see it being produced in the context that i am using it so i cant relate to the answers
-- Edit --
i have had some progress, Names are changing places but i cant seem to match a pattern, So i am thinking that (Q(groups__name=group)) could be the cause of it but i have no idea what this actually does, Can anyone explain this to me? thanks
use
.order_by('-first_name')
instead of
.order_by('-first_name'.desc())
- stands for descending already. otherwise you are trying to call a method on a string instead of QuerySet object

Nested tables in livecycle fall apart on email

I have a form here with a nested table - where each table can dynamically grow, i.e., the inner table (w/ Transit No and Account No) and the outer table (Accounts by ID No). Here is an example:
(Behind the buttons:
Add - $.parent.tbl.Row.instanceManager.addInstance();
Remove - $.parent.instanceManager.removeInstance(this.parent.index); (In
production I make sure there is at least one row to remove...)
In the definition for each table I do not have checked 'Repeat Table for Each Data Item'. This works great. However I did try with that checked and the outcome was the same.
Now, when I email the form and open the attachment, this is what I see:
You can see that the second table didn't make it, and apparently a row was added to the inner table in the first, without any data.
Any ideas on what's going wrong here? And what I can do about it?
Unfortunately I'm not sure what's wrong with your form but I have made a similar form that works - so I can show you how I did it and list a few things that I can think of that can cause problems.
This is what my form looks like and when I e-mail it, it comes out exactly the way it is:
(It has repeatable parent- and childsubforms like yours)
I did it entirely with JS though, no FormCalc and Dollar $igns :D
When a button is pressed I call a function from a Scriptobject.
These are the main parts of my script inside my functions:
Adding a Subform:
var oNewInstance = subform.instanceManager.addInstance(1);
Deleting a Subform:
if (subform.instanceManager.count > subform.instanceManager.occur.min)
{
subform.instanceManager.removeInstance(subform.index);
}
And these are my subforms' properties (in German, but you can figure it out :P):
Your problem might also have completely other reasons though, make sure you don't have any changes in an initialize,docReady, preSubmit and similar actions that occur between sending and opening the sent PDF.
Also before sending it as an e-mail you have to save it in Acrobat as a Reader Extended PDF:
Besides that I've noticed that sometimes problems can occur due to the target version (Selectable in LCD under File > Form Properties > Defaults).
It helped me sometimes to set it to the newest one.

How to add individual objects to django haystack?

I have a search index that I have created using Solr. I want to add individual django objects to the search index.
To remove objects from the solr database we use remove_object.
some = SomFooModel.objects.get(pk=1)
foo = FooIndex()
foo.remove_object(some) #This works
To add it, is there something like add_object or a work around here ?
What I want is.
foo.add_object(some). # there is no such thing
This also does not work. It does not add the object to index.
foo.update_object(some)
I have tried reading the django-haystack documentation but there seems to be nothing that might help.
I did not read the documentation well enough as a result I messed up on the QuerySet part.
foo.update_object(some)
The above does add the object to the index. Its just that I was not searching for it properly.
I was searching for the object after removing it in the following way.
SearchQuerySet().filter(foo=some.foo)
This gave a empty query set always.
SearchQuerySet().models(SomFooModel).filter(foo = some.foo)
This gives the correct result.
Reference

Sitecore sort children by __Created field

I have a Sitecore 6.6 solution running MVC and Razor.
I am have the following line;
#Html.Raw(Sitecore.Context.Database.GetItem(myList.Children.LastOrDefault()["myField1"]).Fields["myField2"])
The above works fine, except the order it sorts in. I need to get the latest item based on the __Created field. LastOrDefault seems to take the last item in the tree, which does not always correspond to the actual latest created item.
Can it be done in one line as the above?
How about this:
myList.GetChildren()
.OrderBy(x => x[Sitecore.FieldIDs.Created])
.Reverse()
.LastOrDefault()
I guess this would work too:
myList.GetChildren()
.OrderBy(x => x.Statistics.Created)
.Reverse()
.LastOrDefault()
Keep in mind though that first all the children will be retrieved and then the sorting will happen.
If you have a lot of children it will be slow.
One general note, you shouldn't do this in the View really. You're putting too much logic in there. Your model should provide the item that you need (last created).