Skip to content

Enable multiple languages to be selected#644

Merged
AdrianDAlessandro merged 4 commits intomainfrom
multiple-languages
Mar 24, 2026
Merged

Enable multiple languages to be selected#644
AdrianDAlessandro merged 4 commits intomainfrom
multiple-languages

Conversation

@AdrianDAlessandro
Copy link
Copy Markdown
Collaborator

@AdrianDAlessandro AdrianDAlessandro commented Mar 20, 2026

Description

This PR allows multiple languages in the Learning resources to be selected. This is necessary because the data contains this.

It does this using the django-multiselectfield package. Which requires a custom MultipleChoiceWidget to be made for the importing resources to work

Fixes #609

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 Mar 23, 2026

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
main/admin.py 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@Sahil590 Sahil590 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. I had a few comments.
Would it be worth adding a check for empty values being passed? I know that the data will be reviewed before importing, but it may be missed.

Comment thread main/admin.py
Comment on lines +111 to +115
@admin.display(description="language", ordering="language")
def get_language_display(self, obj: LearningResource) -> Any:
"""Enable displaying multiple languages in the list display."""
return obj.get_language_display()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The way it's rendered in the admin is through check boxes rather than the way a foreign key field is rendered so not the cleanest. I guess this will always be imported rather than be created manually?

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.

Yea, that's just the default for this multiselectfield. TBH I think the checkboxes are better than the default one that requires you to shift+click to highlight multiple.

This bit of code you've highlighted is for the list display, so that we can see the names of the languages in the table of all learning resources.

Would it be worth adding a check for empty values being passed? I know that the data will be reviewed before importing, but it may be missed.

It's already disallowing empty values for language, so the import will return an error for any empty ones

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK that's fine then. I thought there was something you could add in that file to render it differently. But this implementation works.

@AdrianDAlessandro AdrianDAlessandro merged commit 585e9ec into main Mar 24, 2026
4 checks passed
@AdrianDAlessandro AdrianDAlessandro deleted the multiple-languages branch March 24, 2026 12:08
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.

The LearningResource language field should allow for multiple selections

2 participants