Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Update the admin page to support exporting data
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaimran committed Nov 7, 2023
1 parent dbc1757 commit 30684ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions beta_product/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
from django.contrib import admin
from beta_product.models import UserInterest
from import_export.admin import ExportActionMixin

from import_export import resources
from beta_product.models import UserInterest


class UserInterestResource(resources.ModelResource):
class Meta:
model = UserInterest
fields = ("id", "user__email")


@admin.register(UserInterest)
class UserInterestAdmin(admin.ModelAdmin):
class UserInterestExportActionMixin(ExportActionMixin):
def get_export_resource_class(self):
"""
Returns the ResourceClass to use for this view.
"""
return UserInterestResource


class UserInterestAdmin(UserInterestExportActionMixin, admin.ModelAdmin):
user = UserInterest.user
field = UserInterest.field
list_display = ("user", "field", "unique_identifier", "waitlist")
list_filter = ("user", "field")
search_fields = ("user", "field", "unique_identifier")
ordering = ("user", "field")
readonly_fields = ("user", "field", "unique_identifier")
fieldsets = (
(None, {"fields": ("user", "field", "waitlist", "unique_identifier")}),
)


admin.site.register(UserInterest, UserInterestAdmin)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ whitenoise==6.5.0
django-extensions==3.2.3
snakeviz==2.2.0
gunicorn==21.2.0
django-import-export==3.3.1

0 comments on commit 30684ab

Please sign in to comment.