Skip to content

feat: add APISource model and extend Sensor model with admin view. Closes #1358#1364

Open
drona-gyawali wants to merge 3 commits into
developfrom
model/apisource
Open

feat: add APISource model and extend Sensor model with admin view. Closes #1358#1364
drona-gyawali wants to merge 3 commits into
developfrom
model/apisource

Conversation

@drona-gyawali
Copy link
Copy Markdown
Member

@drona-gyawali drona-gyawali commented May 22, 2026

Description

This PR introduces the apisource and update sensor model with data source tracking abilities.

Related issues

closes : #1358 , #994

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Chore (refactoring, dependency updates, CI/CD changes, code cleanup, docs-only changes).

Checklist

Please complete this checklist carefully. It helps guide your contribution and lets maintainers verify that all requirements are met.

Formalities

  • I have read and understood the rules about how to Contribute to this project.
  • I chose an appropriate title for the pull request in the form: <feature name>. Closes #999
  • My branch is based on develop.
  • The pull request is for the branch develop.
  • I have reviewed and verified any LLM-generated code included in this PR.

Docs and tests

  • I documented my code changes with docstrings and/or comments.
  • I have checked if my changes affect user-facing behavior that is described in the docs. If so, I also included an update to the wiki in the description of this PR.
  • Linter (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved.
  • All the tests gave 0 errors.

GUI changes

Ignore this section if you did not make any changes to the GUI.

  • I have provided a screenshot of the result in the PR.
  • I have created new frontend tests for the new component or updated existing ones.

Review process

  • We encourage you to create a draft PR first, even when your changes are incomplete. This way you refine your code while we can track your progress and actively review and help.
  • If you think your draft PR is ready to be reviewed by the maintainers, click the corresponding button. Your draft PR will become a real PR.
  • If your changes decrease the overall tests coverage (you will know after the Codecov CI job is done), you should add the required tests to fix the problem.
  • Every time you make changes to the PR and you think the work is done, you should explicitly ask for a review. After receiving a "change request", address the feedback and click "request re-review" next to the reviewer's profile picture at the top right.

Signed-off-by: Drona Raj Gyawali <dronarajgyawali@gmail.com>
@drona-gyawali drona-gyawali requested a review from regulartim May 22, 2026 08:09
Copy link
Copy Markdown
Member

@regulartim regulartim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread greedybear/models.py
Comment on lines +41 to +47
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread greedybear/models.py Outdated

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Python variable names are usually snake_case, so apisource -> api_source

Signed-off-by: Drona Raj Gyawali <dronarajgyawali@gmail.com>
@drona-gyawali drona-gyawali requested a review from regulartim May 25, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants