Skip to content

Commit

Permalink
Add admin for the new ProductDependency model #138
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 15, 2024
1 parent 2b35f62 commit 872c144
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions product_portfolio/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from product_portfolio.models import CodebaseResource
from product_portfolio.models import Product
from product_portfolio.models import ProductComponent
from product_portfolio.models import ProductDependency
from product_portfolio.models import ProductItemPurpose
from product_portfolio.models import ProductPackage
from product_portfolio.models import ProductRelationStatus
Expand Down Expand Up @@ -791,3 +792,48 @@ def response_add(self, request, obj, post_url_continue=None):
# so the preserve filters is are properly handled.
request.path += f"?product={obj.product_id}"
return super().response_add(request, obj, post_url_continue)


@admin.register(ProductDependency, site=dejacode_site)
class ProductDependencyAdmin(ProductRelatedAdminMixin):
list_display = (
"dependency_uid",
AsLink("product"),
AsLink("for_package"),
AsLink("resolved_to_package"),
"extracted_requirement",
"scope",
"datasource_id",
"is_runtime",
"is_optional",
"is_resolved",
"is_direct",
"get_dataspace",
)
raw_id_fields = [
"product",
"for_package",
"resolved_to_package",
]
autocomplete_lookup_fields = {"fk": raw_id_fields}
search_fields = ("path",)
list_filter = (
("product", RelatedLookupListFilter),
"is_runtime",
"is_optional",
"is_resolved",
"is_direct",
("for_package", RelatedLookupListFilter),
("resolved_to_package", RelatedLookupListFilter),
)
actions_to_remove = ["copy_to", "compare_with"]

def get_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related(
"for_package__dataspace",
"resolved_to_package__dataspace",
)
)
2 changes: 2 additions & 0 deletions product_portfolio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,8 @@ class ProductDependency(HistoryFieldsMixin, DataspacedModel):
),
)

objects = DataspacedManager.from_queryset(ProductSecuredQuerySet)()

class Meta:
unique_together = (("product", "dependency_uid"), ("dataspace", "uuid"))
verbose_name = "product dependency"
Expand Down

0 comments on commit 872c144

Please sign in to comment.