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
Copy file name to clipboardExpand all lines: README.md
+80-5Lines changed: 80 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ The Data Wizard supports straightforward one-to-one mappings from spreadsheet co
27
27
28
28
# Usage
29
29
30
-
Django Data Wizard provides a JSON (and HTML) API for specifying a data set to import, selecting a serializer, mapping the data columns and identifiers, and (asynchronously) importing the data into the database.
30
+
Django Data Wizard provides a JSON (and HTML) API for specifying a data set to import (by referencing a previously-uploaded file), selecting a serializer, mapping the data columns and identifiers, and (asynchronously) importing the data into the database.
31
31
32
32
## Installation
33
33
@@ -41,7 +41,9 @@ pip install data-wizard
41
41
42
42
See <https://github.com/wq/django-data-wizard> to report any issues.
43
43
44
-
## Celery
44
+
## Initial Configuration
45
+
46
+
### Celery
45
47
46
48
Django Data Wizard requires [Celery] to handle asynchronous tasks, and is usually used with [Redis] as the memory store. These should be configured first or the REST API may not work. Once Redis is installed, you should be able to add the following to your project settings:
47
49
```python
@@ -77,9 +79,82 @@ celery -A myproject worker -l info
77
79
78
80
Note that any time you change your serializer registration, you should reload celery in addition to restarting the Django WSGI instance.
79
81
80
-
## Serializer Registration
82
+
### Data Loader
83
+
84
+
To use Data Wizard with the default configuration, your project should provide a Django model with a `FileField` named `file`. You will want to provide your users with the ability to upload spreadsheets and other files to this model, for example by registering it with [wq.db]. The actual import process can then be triggered after the file is uploaded, for example by adding a form to the detail page ([see below](#new-run)).
85
+
86
+
```python
87
+
# myapp/models.py
88
+
from django.db import models
89
+
90
+
classFileModel(models.Model):
91
+
file= models.FileField(upload_to='spreadsheets')
92
+
# ...
93
+
```
94
+
95
+
```python
96
+
# myapp/rest.py
97
+
from wq.db import rest
98
+
from .models import FileModel
99
+
100
+
rest.router.register_model(
101
+
FileModel,
102
+
fields="__all__",
103
+
)
104
+
```
105
+
106
+
#### Custom FileField Name
107
+
You can use a model with a different `FileField` name by extending `data_wizard.loaders.FileLoader` and setting `DATA_WIZARD_LOADER`:
You can also customize the loader to load data from a [custom wq.io class]. For example, the [Climata Viewer] uses [climata] classes to load data directly from third-party webservices. To do this, extend `data_wizard.loaders.BaseLoader` with a custom `load_io()` function that returns the data from wq.io:
131
+
132
+
```python
133
+
# myapp/models.py
134
+
classWebSource(models.Model):
135
+
url = models.URLField()
136
+
```
137
+
138
+
```myapp/loaders.py
139
+
from data_wizard import loaders
140
+
141
+
classUrlLoader(loaders.BaseLoader):
142
+
defload_io(self):
143
+
source =self.run.content_object
144
+
from wq.io import load_url # or e.g. JsonNetIO
145
+
return load_url(source.url)
146
+
```
147
+
148
+
```python
149
+
# myapp/settings.py
150
+
DATA_WIZARD_LOADER='myapp.loaders.UrlLoader'
151
+
```
152
+
153
+
Note that there still should be a custom model to define the parameters for the IO class, even though there is no file being stored.
154
+
155
+
### Serializer Registration
81
156
82
-
As of version 1.0, Data Wizard relies on serializer classes as the primary means of detecting model fields. These are subclasses of Django REST Framework's [ModelSerializer class]. You can register serializers by creating a `wizard.py` in your app directory (analagous to Django's `admin.py` and wq.db's `rest.py`).
157
+
Data Wizard uses wq.io classes (via the loader) to determine the *source columns* present on the spreadsheet or other data source. It uses Django REST Framework's [ModelSerializer class] to determine the *destination fields* on the database model. You can register serializers by creating a `wizard.py` in your app directory (analogous to Django's `admin.py` and wq.db's `rest.py`). Multiple serializers can be registered with the wizard to support multiple import configurations and destination models.
At least one serializer should be registered in order to use the wizard. Note the use of a human-friendly serializer label when registering. This name should be unique throughout the project, but can be changed later on without breaking existing data. (The class path is used as the actual identifier behind the scenes.)
99
174
100
-
## REST API
175
+
## Run-Time Usage (REST API)
101
176
102
177
The Data Wizard REST API provides the following capabilities. If you are using wq.db, the wizard will automatically register itself with the router. Otherwise, be sure to include `data_wizard.urls` in your URL configuration:
0 commit comments