Comments (3)
It looks like maybe the documentation in the Readme is wrong. The first parameter to pivot
is the row and the second parameter is the column. In order to fill in the date using row_range you'd want
row_range = [date(2022, 3, 28) + timedelta(days) for days in range(8)]
trackings = pivot(trackings, 'date', 'project', 'time', row_range=row_range)
from django-pivot.
Thank you for your very quick response!
Oh, I got the point - if I want to populate dates by row_range - date should always be first parameter (which is row).
I ended up with something like this
dates = [datetime.date(2022, 3, 28), datetime.date(2022, 3, 29), datetime.date(2022, 3, 30), datetime.date(
2022, 3, 31), datetime.date(2022, 4, 1), datetime.date(2022, 4, 2), datetime.date(2022, 4, 3)]
tracks = [{'project': 1, '2022-03-28': datetime.timedelta(seconds=14400), '2022-03-29': None, '2022-03-30': None},
{'project': 2, '2022-03-28': datetime.timedelta(seconds=90), '2022-03-29': None, '2022-03-30': datetime.timedelta(seconds=3900)},
{'project': 3, '2022-03-28': None, '2022-03-29': datetime.timedelta(seconds=21600), '2022-03-30': None}]
for t in tracks:
for d in dates:
if str(d) not in t:
t[str(d)] = None
And get list of dicts as I wanted (to easy iterate in Django template later):
[{'project': 1, '2022-03-28': datetime.timedelta(seconds=14400), '2022-03-29': None, '2022-03-30': None, '2022-03-31': None, '2022-04-01': None, '2022-04-02': None, '2022-04-03': None}, {'project': 2, '2022-03-28': datetime.timedelta(seconds=90), '2022-03-29': None, '2022-03-30': datetime.timedelta(seconds=3900), '2022-03-31': None, '2022-04-01': None, '2022-04-02': None, '2022-04-03': None}, {'project': 3, '2022-03-28': None, '2022-03-29': datetime.timedelta(seconds=21600), '2022-03-30': None, '2022-03-31': None, '2022-04-01': None, '2022-04-02': None, '2022-04-03': None}]
from django-pivot.
As designed
from django-pivot.
Related Issues (20)
- Example to render pivot table in template HOT 11
- Allow default values if no records are found HOT 2
- unexpected type conversion HOT 3
- Blocker - No readme.srt found in package HOT 1
- force_text in django_pivot.utils.py is depricated for django >=3.0 HOT 1
- Django Rest FrameWorks HOT 2
- Missing files in sdist
- is it possible to remove doublescore for lookup columns? HOT 2
- Total column HOT 1
- ModuleNotFoundError: No module named 'django_pivot' HOT 3
- TypeError: annotate() keywords must be strings + FIX HOT 2
- New version
- Bug with binary fields HOT 1
- Pivot on Union Queryset : Calling QuerySet.distinct() after union() is not supported. HOT 1
- Column values that contain spaces don't work (and doc might improve a smidgeon) HOT 1
- Queryset and pivot table ordering HOT 1
- Cumulative aggregation
- Add Support for multiples data fields HOT 2
- Pivot returns List instead of ValuesQueryset HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-pivot.