I get records by api call. I need to get number of records created each month. Ho can I do that?
Thanks in advance.
I get records by api call. I need to get number of records created each month. Ho can I do that?
Thanks in advance.
Create a query for the records in the month and use the count()
method on that queryset. (More detailed information, such as the definition of the model being queried, would be required before we can provide a more detailed or specific answer.)
Thank you for your quick response, Ken!
I get data from a remote (third party) database via API.
url = "https://some_url"
header = {"Authorization" : "Basic xxx"}
response = requests.get(url, headers=header)
records = response.json()
I can get total by num = len(records)
, but need to get total for each month.
Here is an example of records structure (model?):
{'id': 'someid', 'recordId': 'someid', 'createdAt': '2024-12-04T15:19:41.757Z', 'fields': {'Name': 'somename', 'Контакт': ['xxx'], 'список/форма': ['xxx'], 'менеджер': 'Ира', 'статус': 'Подал/а на формы', 'Department': ['CD'], 'First Name': 'Carlos', 'Last Name': 'xxx', 'Email/s': ['xxx'], 'Gender': 'Male', 'Country': 'CO', 'Кастинг': '9', 'Дата презентации / дата передачи': '2024-12-04', 'Category': ['xxx'], 'Page RS': ['xxx']}, 'link': 'some_link'}
Edited to add: Ideally I’d like to get an array like {‘January’: 100, ‘February’: 120, ‘March’: 150 etc…}
This would be a standard python operation and not anything specifically related to Django.
Create your dictionary to hold the results, initialize each value to zero. Iterate over all the rows returned. Identify the month for each row, and add one to the corresponding dict key.
Thanks! I was not sure if I need to research Django or python docs.
By the way. How can I log in on my computer under the same username as on my phone? When I log out on computer, trying to log in with the other username, I can’t. I thought I will be able to enter another username, but it doesn’t let me. It logs me right away after I just click the “Login”.