feat: add APISource model and extend Sensor model with admin view. Closes #1358#1364
feat: add APISource model and extend Sensor model with admin view. Closes #1358#1364drona-gyawali wants to merge 3 commits into
Conversation
Signed-off-by: Drona Raj Gyawali <dronarajgyawali@gmail.com>
regulartim
left a comment
There was a problem hiding this comment.
Hey @drona-gyawali ! Looks good so far! :) Aside from my comments, please merge develop and re-create the migration. I just merged migration 0053 and 0054.
| class AutonomousSystem(models.Model): | ||
| asn = models.IntegerField(primary_key=True) | ||
| name = models.CharField(max_length=256, blank=True) | ||
|
|
||
| def __str__(self): | ||
| return f"{self.name} ({self.asn})" if self.name else str(self.asn) | ||
|
|
There was a problem hiding this comment.
The diff looks like you moved the AS above the sensor model but did not make any changes to it. If there is no good reason to do that, I would prefer to not make this change.
There was a problem hiding this comment.
Hi @regulartim , You're completely right that it adds noise to the diff, and I apologize for that!
The reason behind this is that the Sensor model uses AutonomousSystem as a Foreign Key and the models were ordered incorrectly, which was throwing a Python NameError because Sensor was trying to reference a model that hadn't been defined yet.
|
|
||
| autonomous_system = models.ForeignKey(AutonomousSystem, on_delete=models.SET_NULL, related_name="sensors", null=True, blank=True) | ||
|
|
||
| apisource = models.ForeignKey(APISource, on_delete=models.CASCADE, related_name="sensors", null=True, blank=True) |
There was a problem hiding this comment.
I think I would not set on_delete=models.CASCADE here. We are referencing the Sensor in the IOC model. Even if the user, that create the underlying API source is deleted, we want to keep this information, right?
There was a problem hiding this comment.
Also, Python variable names are usually snake_case, so apisource -> api_source
Signed-off-by: Drona Raj Gyawali <dronarajgyawali@gmail.com>
Description
This PR introduces the apisource and update sensor model with data source tracking abilities.
Related issues
closes : #1358 , #994
Type of change
Checklist
Please complete this checklist carefully. It helps guide your contribution and lets maintainers verify that all requirements are met.
Formalities
<feature name>. Closes #999develop.develop.Docs and tests
Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.GUI changes
Ignore this section if you did not make any changes to the GUI.
Review process