Skip to content

Commit 3a8a173

Browse files
committed
The changes made in this commit include:
- Updated README.md - Added images for data import instructions
1 parent c349119 commit 3a8a173

File tree

8 files changed

+47
-0
lines changed

8 files changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,50 @@ Open `http://localhost:8000` to view it in the browser
7979

8080
## [Django admin](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/) web interface (user should be `is_staff` or `is_superuser`)
8181
`http://localhost:8000/admin`
82+
83+
84+
## Import data from admin interface
85+
86+
For data import used [django-import-export](https://django-import-export.readthedocs.io/en/latest/index.html) library
87+
88+
The code consists of Django resource classes that are used for importing and exporting CSV files using the Django Import-Export library:
89+
1. `SignalResource` - this resource class is used for importing `Signal` models:
90+
* Defines various fields such as `name`, `display_name`, `pathogen`, `signal_type`, and `source`.
91+
* Defines the `before_import_row` method, which is called before importing each row and allows for pre-processing of the data.
92+
* Includes methods like `is_url_in_domain` to check if a URL belongs to a specific domain, `fix_boolean_fields` to handle boolean fields, and `process_links` to process the links field.
93+
94+
2. `SignalBaseResource` - This resource class is used for updating already created `Signal` models `base` fields with base Signals.
95+
* Defines various fields such as `name`, `display_name`, `base`, and `source`.
96+
* Defines the `before_import_row` method, which is called before importing each row and allows for pre-processing of the data.
97+
* The `process_base` method is responsible for processing the `base` field by retrieving the corresponding `Signal` object based on the provided `name` and `source`.
98+
99+
3. `SourceSubdivisionResource` - this resource class is used for importing `SourceSubdivision` models
100+
* It defines fields such as `name`, `display_name`, `description`, `data_source`, and `links`.
101+
* It includes the `before_import_row` method for pre-processing each row before importing.
102+
* The `process_links` method is responsible for processing the `links` field by creating `Link` objects based on the provided URLs.
103+
* The `process_datasource` method processes the `data_source` field by creating or retrieving a `DataSource` object based on the provided name.
104+
105+
These resource classes provide a structured way to import CSV files. They define the fields, handle pre-processing of data, and interact with the corresponding models and related objects.
106+
107+
### Import data flow
108+
109+
To import data from a CSV file must meet the requirements:
110+
* CSV file should be properly formatted and contains all the required fields for importing, as specified by the resource classes (`SignalResource`, `SignalBaseResource`, `SourceSubdivisionResource`). The header row of the CSV file should match the field names defined in the resource classes.
111+
* It should not contain empty rows from the CSV file before importing. Empty rows may cause validation errors during the import process.
112+
* Colums should be saparateb by `","`
113+
114+
Othervice you will receive Errors during import process:
115+
![Import errors](./docs/image-3.png)
116+
117+
118+
1. Import `SourceSubdivision` instances with `SourceSubdivisionResource` - [http://localhost:8000/admin/datasources/sourcesubdivision/import/](http://localhost:8000/admin/datasources/sourcesubdivision/import/)
119+
![Import `SourceSubdivision` instances](./docs/image.png)
120+
![Confirm importing `SourceSubdivision` instances](./docs/image-1.png)
121+
122+
2. Import `Signal` instances with `SignalResource` - [http://localhost:8000/admin/signals/signal/import/](http://localhost:8000/admin/signals/signal/import/)
123+
![Import `Signal` instances](./docs/image-2.png)
124+
![Confirm importing `Signal` instances](./docs/image-4.png)
125+
126+
3. Import `Signal.base` fields with `SignalBaseResource` - [http://localhost:8000/admin/signals/signal/import/](http://localhost:8000/admin/signals/signal/import/)
127+
![Import `Signal.base` field](./docs/image-5.png)
128+
![Confirm importing `Signal.base` fields](./docs/image-6.png)

docs/image-1.png

171 KB
Loading

docs/image-2.png

77.7 KB
Loading

docs/image-3.png

140 KB
Loading

docs/image-4.png

127 KB
Loading

docs/image-5.png

77.7 KB
Loading

docs/image-6.png

111 KB
Loading

docs/image.png

54 KB
Loading

0 commit comments

Comments
 (0)