Skip to content

Prepare models before new framework#572

Merged
AdrianDAlessandro merged 15 commits intomainfrom
prep-for-568
Feb 10, 2026
Merged

Prepare models before new framework#572
AdrianDAlessandro merged 15 commits intomainfrom
prep-for-568

Conversation

@AdrianDAlessandro
Copy link
Copy Markdown
Collaborator

@AdrianDAlessandro AdrianDAlessandro commented Feb 4, 2026

Description

This PR updates the models and the populate_db script in preparation for expanding the database (#568). These changes include:

  • Improved validation, abstraction and testing for populate_db.py
  • Adding a unique slug field to most of the existing models through the creation of two abstract parent classes: NamedModel and SluggedModel
  • Including full test coverage for the previously untested models.py

Fixes #571

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Technical work (non-breaking, change which is work as part of a new feature)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass (eg. python -m pytest)
  • The documentation builds and looks OK (eg. mkdocs serve)
  • Pre-commit hooks run successfully (eg. pre-commit run --all-files)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added or an issue has been opened to tackle that in the future. (Indicate issue here: # (issue))

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prepares the codebase for future database schema expansion by adding slug fields to Category and Skill models, improving the populate_db.py script with better validation and error handling, and adding comprehensive test coverage for the models module. The changes introduce two abstract base classes (NamedModel and SluggedModel) that provide shared functionality for name, description, and auto-generated slug fields.

Changes:

  • Added abstract base classes NamedModel and SluggedModel to provide shared fields and behavior
  • Added unique slug fields to Category and Skill models with auto-generation on save
  • Refactored populate_db.py to use a centralized add_object_to_db function with validation and logging
  • Added comprehensive test coverage for all model classes and validation logic

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
main/models.py Introduced abstract base classes (NamedModel, SluggedModel) and updated Category, Skill, and SkillLevel models to use them, adding slug fields with auto-generation
main/migrations/0011_category_slug_skill_slug_alter_skilllevel_level.py Schema migration adding slug fields to Category and Skill models and making SkillLevel.level unique
scripts/populate_db.py Refactored to use new add_object_to_db helper function with validation, error handling, and logging for robustness
tests/main/test_models.py Added comprehensive test coverage for all models including validation logic, abstract base classes, and model relationships
tests/scripts/test_populate_db.py Enhanced tests with validation error scenarios and added tests for the new add_object_to_db function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main/models.py Outdated
Comment thread tests/main/test_models.py Outdated
Comment thread main/models.py
Comment thread scripts/populate_db.py Outdated
Comment thread scripts/populate_db.py Outdated
Comment thread tests/main/test_models.py
Comment thread tests/main/test_models.py Outdated
Comment thread main/migrations/0011_category_slug_skill_slug_alter_skilllevel_level.py Outdated
Comment thread main/models.py
Comment thread main/models.py
Comment on lines +108 to +109
if self.category_id is None:
raise ValidationError({"category": _("A skill must belong to a category.")})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wouldn't modify the category field above with null=False, blank=False do the same job?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, those are the default values, so it is already set. This is only required because of the below check, where I'm checking self.category.parent_category is not None, which will error if self.category is None. This happens in the Admin if you try to create a skill without selecting a category.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's odd that the Admin itself does not respect the requirement that a certain field must not be none/null. Ok, so be it...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The admin does check it, but my custom clean method is run regardless, which is what causes the problem

Comment thread main/models.py
Comment thread scripts/populate_db.py Outdated
@AdrianDAlessandro AdrianDAlessandro merged commit 9955f80 into main Feb 10, 2026
4 checks passed
@AdrianDAlessandro AdrianDAlessandro deleted the prep-for-568 branch February 10, 2026 15:19
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.

Prepare the code for the new framework schema

3 participants