This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the admin page to support exporting data
- Loading branch information
Showing
2 changed files
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |