Skip to content

Commit

Permalink
improvements to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
george-silva committed Oct 21, 2024
1 parent dbcb5d3 commit ee01b5a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/planscape/datasets/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,34 @@
class CategoryAdmin(TreeAdmin):
form = CategoryAdminForm
search_fields = ["name"]
list_display = ("id", "name", "order", "dataset")

def get_changeform_initial_data(self, request):
return {"created_by": request.user}

def get_form(self, request, obj=None, change=False, **kwargs):
form = super().get_form(request, obj, change, **kwargs)
if not change:
form.created_by = request.user
return form


class DatasetAdmin(admin.ModelAdmin):
list_filter = ["visibility"]
search_fields = ["organization__name__icontains", "name"]
autocomplete_fields = ["organization"]
form = DatasetAdminForm
list_display = ("id", "name", "visibility", "organization")
list_display_links = (
"id",
"name",
)

def get_form(self, request, obj=None, change=False, **kwargs):
form = super().get_form(request, obj, change, **kwargs)
if not change:
form.created_by = request.user
return form


class DataLayerAdmin(admin.ModelAdmin):
Expand All @@ -25,6 +46,23 @@ class DataLayerAdmin(admin.ModelAdmin):
"name",
]
autocomplete_fields = ["organization", "created_by", "dataset", "category"]
list_display = (
"id",
"name",
"status",
"type",
"geometry_type",
"dataset",
"category",
"organization",
)
list_display_links = (
"id",
"name",
"status",
"type",
"geometry_type",
)


admin.site.register(Dataset, DatasetAdmin)
Expand Down
6 changes: 5 additions & 1 deletion src/planscape/datasets/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class Meta:
class CategoryAdminForm(movenodeform_factory(Category)):
order = forms.IntegerField(required=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["created_by"].disabled = True

class Meta:
model = Category
fields = (
"organization",
"created_by",
"dataset",
"created_by",
"name",
"order",
)
3 changes: 3 additions & 0 deletions src/planscape/organizations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class OrganizationAdmin(admin.ModelAdmin):
search_fields = ["name"]
list_display = ("id", "name", "type")
list_display_links = ("id", "name")
list_filter = ("type",)


admin.site.register(Organization, OrganizationAdmin)

0 comments on commit ee01b5a

Please sign in to comment.