Skip to content

Commit

Permalink
Merge pull request #330 from sbs2001/315-django-admin
Browse files Browse the repository at this point in the history
Add django admin  functionality for searching and filtering objects
  • Loading branch information
sbs2001 authored Feb 5, 2021
2 parents 6eddacc + bd65fe4 commit 1d6bade
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions vulnerabilities/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
# Copyright (c) nexB Inc. and others. All rights reserved.
# http://nexb.com and https://github.com/nexB/vulnerablecode/
# The VulnerableCode software is licensed under the Apache License version 2.0.
# Data generated with VulnerableCode require an acknowledgment.
Expand All @@ -18,7 +18,7 @@
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# VulnerableCode should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
# VulnerableCode is a free software code scanning tool from nexB Inc. and others.
# VulnerableCode is a free software tool from nexB Inc. and others.
# Visit https://github.com/nexB/vulnerablecode/ for support and download.

from django.contrib import admin
Expand All @@ -34,22 +34,24 @@

@admin.register(Vulnerability)
class VulnerabilityAdmin(admin.ModelAdmin):
pass
search_fields = ["cve_id"]


@admin.register(VulnerabilityReference)
class VulnerabilityReferenceAdmin(admin.ModelAdmin):
pass
search_fields = ["vulnerability__cve_id", "reference_id", "url"]


@admin.register(Package)
class PackageAdmin(admin.ModelAdmin):
pass
list_filter = ("type", "namespace")
search_fields = ["name"]


@admin.register(PackageRelatedVulnerability)
class PackageRelatedVulnerabilityAdmin(admin.ModelAdmin):
pass
list_filter = ("is_vulnerable", "package__type", "package__namespace")
search_fields = ["vulnerability__cve_id", "package__name"]


@admin.register(Importer)
Expand Down
3 changes: 3 additions & 0 deletions vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class PackageRelatedVulnerability(models.Model):
vulnerability = models.ForeignKey(Vulnerability, on_delete=models.CASCADE)
is_vulnerable = models.BooleanField()

def __str__(self):
return f"{self.package.package_url} {self.vulnerability.cve_id}"

class Meta:
unique_together = ("package", "vulnerability")
verbose_name_plural = "PackageRelatedVulnerabilities"
Expand Down

0 comments on commit 1d6bade

Please sign in to comment.