You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**@wq/analyst** is a [@wq/app plugin] providing interactive React tables and charts. @wq/analyst is primarily intended as a client for [Django REST Pandas].
Copy file name to clipboardExpand all lines: docs/config.md
+71-8
Original file line number
Diff line number
Diff line change
@@ -11,25 +11,65 @@ wq_config:
11
11
12
12
### URL Configuration
13
13
14
+
To use [Django REST Pandas] in your project, you will generally need to define an [API view][api] and register it with urls.py as shown below:
15
+
14
16
```python
15
17
# urls.py
16
-
from django.conf.urls import patterns, include, url
17
-
18
+
from django.urls import path
18
19
from .views import TimeSeriesView
19
-
urlpatterns = patterns('',
20
-
url(r'^data', TimeSeriesView.as_view()),
20
+
21
+
urlpatterns = (
22
+
path("data", TimeSeriesView.as_view()),
21
23
)
22
24
23
-
#This is only required to support extension-style formats (e.g. /data.csv)
25
+
#The following is required to support extension-style formats (e.g. /data.csv)
24
26
from rest_framework.urlpatterns import format_suffix_patterns
25
27
urlpatterns = format_suffix_patterns(urlpatterns)
26
28
```
27
29
30
+
When [using DRP with the wq framework][wq-setup], you can instead register a [`PandasViewSet`][PandasViewSet] subclass with [wq.db.rest.router]. wq.db provides extension-style formats by default.
31
+
32
+
```
33
+
from wq.db import rest
34
+
from .views import TimeSeriesViewSet
35
+
36
+
rest.router.add_page(
37
+
"data",
38
+
{
39
+
"url": "data",
40
+
"template": "table",
41
+
"table": {"url": "/data.csv"},
42
+
},
43
+
TimeSeriesViewSet,
44
+
)
45
+
```
46
+
28
47
### Customizing Renderers
29
48
30
-
You can override the [default renderers][renderers] by setting `PANDAS_RENDERERS` in your `settings.py`, or by overriding `renderer_classes` in your individual view(s). `PANDAS_RENDERERS` is defined separately from Django REST Framework's own `DEFAULT_RENDERER_CLASSES` setting, in case you want to have DRP-enabled views intermingled with regular DRF views.
49
+
DRP provides a set of [default renderers][renderers] that you can oveeride by setting `REST_PANDAS["RENDERERS"]` in your `settings.py`, or by overriding `renderer_classes` in your individual view(s). `REST_PANDAS["RENDERERS"]` should be a list or tuple of string paths pointing to one or more Django REST Framework renderer classes.
50
+
51
+
The default `REST_PANDAS["RENDERERS"]` setting is as follows:
52
+
53
+
```python
54
+
REST_PANDAS= {
55
+
"RENDERERS": (
56
+
"rest_pandas.renderers.PandasHTMLRenderer",
57
+
"rest_pandas.renderers.PandasCSVRenderer",
58
+
"rest_pandas.renderers.PandasTextRenderer",
59
+
"rest_pandas.renderers.PandasJSONRenderer",
60
+
"rest_pandas.renderers.PandasExcelRenderer",
61
+
"rest_pandas.renderers.PandasOldExcelRenderer",
62
+
"rest_pandas.renderers.PandasPNGRenderer",
63
+
"rest_pandas.renderers.PandasSVGRenderer",
64
+
),
65
+
)
66
+
```
67
+
68
+
> When [using DRPwith the wq framework][wq-setup], `"rest_pandas.renderers.PandasHTMLRenderer"`is automatically replaced with`"wq.db.rest.renderers.HTMLRenderer"` by default.
69
+
70
+
`REST_PANDAS["RENDERERS"]`is similar to Django REST Framework's own `DEFAULT_RENDERER_CLASSES` setting, but defined separately in case you plan to have DRP-enabled views intermingled with regular DRF views. That said, it is also possible to include DRP renderers in `DEFAULT_RENDERER_CLASSES`. To do so, extend `PandasMixin` in you view or set `Meta.list_serializer_class` explicitly on your serializer. Otherwise, you may get an error saying the serializer output is not a `DataFrame`.
31
71
32
-
You can also include DRP renderers in `DEFAULT_RENDERER_CLASSES`. In that case, extend `PandasMixin` or set `list_serializer_class` on your serializer. Otherwise, you may get an error saying the serializer output is not a `DataFrame`. In short, there are three paths to getting DRP renderers working with your views:
72
+
In short, there are three paths to getting DRP renderers working with your views:
33
73
34
74
1. Extend [PandasView], [PandasSimpleView], or [PandasViewSet], and use the `PANDAS_RENDERERS` setting (which defaults to the list above).
35
75
2. Extend [PandasMixin] and customize `REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES']` to add one or more `rest_pandas` renderers.
@@ -45,6 +85,20 @@ class TimeSeriesView(PandasMixin, ListAPIView):
45
85
...
46
86
```
47
87
88
+
### Field Labels
89
+
90
+
By default, Django REST Pandas will update the dataframe columns to use the `label` attribute of defined serializer fields, and/or the `verbose_name` attribute of any underlying model fields. To disable this functionality (and use the field names as column names), set`REST_PANDAS["APPLY_FIELD_LABELS"]` to false.
91
+
92
+
```python
93
+
REST_PANDAS = {
94
+
"APPLY_FIELD_LABELS": True, # Default in DRP 2.0
95
+
}
96
+
97
+
REST_PANDAS = {
98
+
"APPLY_FIELD_LABELS": False, # Compatible with DRP 1.x
99
+
}
100
+
```
101
+
48
102
### Date Formatting
49
103
50
104
By default, Django REST Framework will serialize dates as strings before they are processed by the renderer classes. In many cases, you may want to preserve the dates as`datetime` objects and let Pandas handle the rendering. To do this, define an explicit [DateTimeField] or [DateField] on your DRF serializer andset`format=None`:
@@ -65,9 +119,18 @@ Alternately, you can disable date serialization globally by setting `DATETIME_FO
**@wq/analyst** is a @wq/app plugin providing interactive React tables and charts. @wq/analyst is primarily intended as a client for [Django REST Pandas].
0 commit comments