Skip to content

Commit

Permalink
add option for adding data in bulk
Browse files Browse the repository at this point in the history
- used the django-import-export package
- tutorials can be now added in bulk with admin access
- all populat file formats supported (xls, csv, yaml etc)
  • Loading branch information
Bhupesh-V committed Aug 13, 2019
1 parent 2b5268e commit 3be6e83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

# Register your models here.
from . models import tutorial, tag
from import_export.admin import ImportExportModelAdmin
from import_export import resources, fields
from import_export.widgets import ManyToManyWidget

admin.site.register(tag)
admin.site.register(tutorial)

class TutorialResource(resources.ModelResource):
tags = fields.Field(
column_name='tags',
attribute='tags',
widget=ManyToManyWidget(tag, ',', 'name'))
class Meta:
model = tutorial
exclude = ('id',)
export_order = ('title', 'link', 'tags', 'category', 'created_date')
import_id_fields = ('title', 'link')


@admin.register(tutorial)
class TutorialAdmin(ImportExportModelAdmin):
resource_class = TutorialResource
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ requests==2.18.4
beautifulsoup4==4.7.1
lxml==4.4.0
djangorestframework==3.10.0
python-dotenv==0.10.3
python-dotenv==0.10.3
django-import-export==1.2.0
1 change: 1 addition & 0 deletions tutorialdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'app',
'api',
'taggie',
'import_export',
]

REST_FRAMEWORK = {
Expand Down

0 comments on commit 3be6e83

Please sign in to comment.