added import and export data from admin dashboard
This commit is contained in:
parent
578ff04956
commit
9b8fa8721f
|
@ -1,12 +1,34 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from import_export import resources
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
|
||||
from .models import InvitedGuest
|
||||
|
||||
class InvitedGuestAdmin(admin.ModelAdmin):
|
||||
class ExportInvitedGuestResource(resources.ModelResource):
|
||||
class Meta:
|
||||
model = InvitedGuest
|
||||
fields = ('name', 'attending')
|
||||
export_order = ('name', 'attending')
|
||||
exclude = 'rsvpCode'
|
||||
|
||||
class ImportInvitedGuestResource(resources.ModelResource):
|
||||
class Meta:
|
||||
model = InvitedGuest
|
||||
fields = ('name', 'rsvpCode')
|
||||
skip_unchanged = True
|
||||
report_skipped = False
|
||||
import_id_fields = ['name']
|
||||
|
||||
|
||||
class InvitedGuestAdmin(ImportExportModelAdmin):
|
||||
resource_class = ImportInvitedGuestResource
|
||||
fields = ['name', 'rsvpCode', 'attending']
|
||||
list_display = ('name', 'rsvpCode', 'attending')
|
||||
search_fields = ['name']
|
||||
list_filter = ['attending']
|
||||
def get_export_resource_class(self):
|
||||
return ExportInvitedGuestResource
|
||||
|
||||
|
||||
admin.site.register(InvitedGuest, InvitedGuestAdmin)
|
|
@ -27,7 +27,6 @@ DEBUG = True
|
|||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
|
@ -37,6 +36,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'import_export',
|
||||
'bigday'
|
||||
]
|
||||
|
||||
|
@ -118,4 +118,4 @@ USE_TZ = True
|
|||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_URL = '/static/'
|
Loading…
Reference in New Issue