I'm using Ransack for some simple searching of one of my models.
I would like to add a dropdown to the search with entries like 'Today', 'Yesterday', 'Current week', etc which would operate on the created_at field. Also it would be nice to have an entry in this dropdown to reveal 2 date boxes to pick a custom date range. How do I go about this?
One way that I can think of doing this is for the dropdown to populate the two (hidden) date boxes via JavaScript, I just don't know how I could easily reselect the proper entry in the dropdown when reloading the page.
use this
distance_of_time_in_words(obj.created_at,Time.now)+" ago"
This will return result like this:
about 2 hours ago
Related
How to get date picker in Django Admin Filter?
using simple list_filter will get me text selection: Any date, last 7 days, last months etc. But I want simple datepicker, so i can choose just one date... I found django-admin-daterange but I don't need range - just ONE date..
I'm trying to build a dashboard with a month sorted view - where in an ideal situation the user would select the month from the dropdown and the represented data would change accordingly.
So far my approach has been to query the data into a separate sheet using the drop-down option, but I'm facing a problem with the All option.
Example:
My drop-down contains months
Jan
Feb
Mar
...
...
All
This works until the "All" option is selected, as there is no All in my original data. I understand there's other formats of using a date range instead, but I'm curious to know how this can be done as well.
Do let me know if this needs to be clarified!
Thank you.
you can add IF switch:
=IF(A1="All", QUERY(_full_query_here_), QUERY(_query_that_checks_A1_for_month_))
I'm using rails_admin. Unfortunately I can't get to override a sort action on a specific model. I just want to show all users (sort action, when the title is clicked) created_at 1 day ago or etc. Any idea?
I am expecting that you want a custom filter which allows user to select options like "One Day Ago", "One Week Ago", "One Month Ago".
Yes you can implement this functionality using the scoping the queries. Here is the link for same. Scoping Queries
Also if you want to customize the values displayed in the column the you can take a look at this Railscast Active Admin Episode
In this video they have explained the column customization for price column (from 4.25 to 7.15).
I'm working on a web site and i wanna separate a input into two parts (two dropdown lists) and after that concatenate them together and afterwards put that value into my database.
It goes something like this:
I want users to input a product Age, and i want to give them a dropdown list where they can select a number and a dropdown list where they can select if it's a day, week or month.
So they can select something like "1" + "day" or "4" + "weeks", and have a "1 day" or "4 weeks" in my Age database column. How can i do this?
Not a direct answer to your question, and maybe OT, but I would suggest you use a Date column in your database. This will allow you you to perform comparisons (like before / after), and ordering in SQL.
You can always the distance_of_time_in_words and distance_of_time_in_words_to_now helpers (documentation) to generate human readable time like 4 days ago, etc.
With the following formula in my calculated column which formats the date & time column:
=TEXT(DatePublished,"d/m/yyyy")
How may i make sure the other dates are disabled when users create a custom list item, ie. users have actually no option to select any other dates?
Or maybe disable the calendar when they click on the calendar icon?
A workaround or am i missing out a lot?
oh my, sorry. I missed out something big, could have used the already available 'Created' field. Then create another calculated column 'DatePublished' with formula:
=TEXT(Created,"dd/m/yyyy")