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
+47Lines changed: 47 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -79,3 +79,50 @@ Open `http://localhost:8000` to view it in the browser
79
79
80
80
## [Django admin](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/) web interface (user should be `is_staff` or `is_superuser`)
81
81
`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
+

116
+
117
+
118
+
1. Import `SourceSubdivision` instances with `SourceSubdivisionResource` - [http://localhost:8000/admin/datasources/sourcesubdivision/import/](http://localhost:8000/admin/datasources/sourcesubdivision/import/)
0 commit comments