Is there any way to append a non-Django supplied value to a query?
For instance, to find out if a store closed, I may run a function called get_closed_stores()
which returns a list of closed stores.
Stores Closed
[00090, 00240, 00306, 00438, 03005, 05524]
Great, now we have store numbers for stores that are closed. Lets get those actual store objects.
Query
Store.objects.filter(
store_number__in=[00090, 00240, 00306, 00438, 03005, 05524]
)
We now have the QuerySet, but we have absolutely no way to detect when the store closed, because the database doesn't contain any information about emergency closings, but Sharepoint does. So back at get_closed_stores()
we can return the Date Closed alongside the store number so our Closed Stores List (dictionary) would look more like below:
Store List with Dates
{
[00090, '1/28/19 5:00PM'],
[00240,'1/28/19 5:00PM'],
[00306, '1/28/19 5:00PM'],
[00438,'1/28/19 5:00PM'],
[03005,'1/28/19 5:00PM'],
[05524, '1/28/19 5:00PM']
}
Now that the dates are with my store numbers, I can add this to my Queryset (ideally) and access it from my front end.
So annotate()
would be ideal here if I were working with anything Django ORM related, but when it comes to "injecting" external data, what is it I'm looking for?
I can absolutely just make the call for each store from JS on my front end but I would rather not if I can get around it