Search through posts
If not already done so, please first follow the tutorial for the postv1 micro-app, to get a grasp on what it does, the prerequisites and some specific details of the ONEm SDK.
This version adds the following:
- persistent post storage in our local sqlite database
- search capabilities
models.py file describes our Post entity and its attributes.
1 2 3 4 5 6 7 8 9
AddPostView.post method from
views.py file was modified in order to store the posts in the database.
The relevant piece of code is the one below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Let's run the below 2 commands in the root folder of our postv2 app to create the schema migrations and the database tables:
As mentioned, in this version we've added a search capability. Let's look into the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Our form has only one form item in which we prompt the user with some input, be it a specific post code or a keyword to search for.
FormItem has specific properties like
description etc. Should we want further input from the user, we can simply add new
FormItem items in the above list.
Form contains the form items in the
body attribute and requires a
path so ONEm platform can perform an HTTP POST callback (as indicated in the
method attribute) with a payload containing the user search term.
post method grabs the
keyword and handles the search logic. Worth mentioning here is that if we get multiple matches for the given keyword, we use a
Menu to present the results, otherwise we redirect to post detail.