Skip to content

Commit 1d6bade

Browse files
authored
Merge pull request #330 from sbs2001/315-django-admin
Add django admin functionality for searching and filtering objects
2 parents 6eddacc + bd65fe4 commit 1d6bade

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

vulnerabilities/admin.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
33
# http://nexb.com and https://github.com/nexB/vulnerablecode/
44
# The VulnerableCode software is licensed under the Apache License version 2.0.
55
# Data generated with VulnerableCode require an acknowledgment.
@@ -18,7 +18,7 @@
1818
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
1919
# VulnerableCode should be considered or used as legal advice. Consult an Attorney
2020
# for any legal advice.
21-
# VulnerableCode is a free software code scanning tool from nexB Inc. and others.
21+
# VulnerableCode is a free software tool from nexB Inc. and others.
2222
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2323

2424
from django.contrib import admin
@@ -34,22 +34,24 @@
3434

3535
@admin.register(Vulnerability)
3636
class VulnerabilityAdmin(admin.ModelAdmin):
37-
pass
37+
search_fields = ["cve_id"]
3838

3939

4040
@admin.register(VulnerabilityReference)
4141
class VulnerabilityReferenceAdmin(admin.ModelAdmin):
42-
pass
42+
search_fields = ["vulnerability__cve_id", "reference_id", "url"]
4343

4444

4545
@admin.register(Package)
4646
class PackageAdmin(admin.ModelAdmin):
47-
pass
47+
list_filter = ("type", "namespace")
48+
search_fields = ["name"]
4849

4950

5051
@admin.register(PackageRelatedVulnerability)
5152
class PackageRelatedVulnerabilityAdmin(admin.ModelAdmin):
52-
pass
53+
list_filter = ("is_vulnerable", "package__type", "package__namespace")
54+
search_fields = ["vulnerability__cve_id", "package__name"]
5355

5456

5557
@admin.register(Importer)

vulnerabilities/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ class PackageRelatedVulnerability(models.Model):
144144
vulnerability = models.ForeignKey(Vulnerability, on_delete=models.CASCADE)
145145
is_vulnerable = models.BooleanField()
146146

147+
def __str__(self):
148+
return f"{self.package.package_url} {self.vulnerability.cve_id}"
149+
147150
class Meta:
148151
unique_together = ("package", "vulnerability")
149152
verbose_name_plural = "PackageRelatedVulnerabilities"

0 commit comments

Comments
 (0)