Skip to content

feat: create table UserPracticeAreaSecondaryXref (#680)#687

Open
egcuriel wants to merge 8 commits into
hackforla:mainfrom
egcuriel:feature/680-create_table_UserPracticeAreaSecondaryXref
Open

feat: create table UserPracticeAreaSecondaryXref (#680)#687
egcuriel wants to merge 8 commits into
hackforla:mainfrom
egcuriel:feature/680-create_table_UserPracticeAreaSecondaryXref

Conversation

@egcuriel

Copy link
Copy Markdown
Member

Fixes #680

What changes did you make?

  • Models: Created the UserPracticeAreaSecondaryXref model to serve as the custom through table for the practice_area_secondary many-to-many relationship.
  • Admin: Registered the new model, added delayed M2M save logic, and implemented explicit form validation to prevent users from selecting the same practice area as both primary and secondary.
  • API: Updated the UserSerializer to support the new secondary practice area structure. Overrode the Django update method to sanitize the incoming payload, silently discarding duplicate primary/secondary assignments before saving.
  • Tests: Updated test_models.py assertions to align with the implemented practice_areas_secondary reverse relation.
  • Scripts: Updated scripts/validate_mkdocs.sh to use modern Docker compose syntax.

Why did you make the changes (we will use this info to test)?

  • Created the UserPracticeAreaSecondaryXref model to setup the necessary backend table that joins a user with multiple practice areas
  • To provide data integrity from Admin, custom validation was added in the Django Admin to block staff from saving duplicate primary/secondary records and displaying an error message to guide them to correct it.
  • Implemented defensive data handling in the serializer to gracefully handle conflicting data and protect backend database integrity, preventing HTTP errors that could crash or break frontend applications.
  • Updated existing model tests to ensure suite stability after the schema changes, and modernized infrastructure scripts to match current project standards.

Screenshots of Proposed Changes To The Website

Django Admin Validation- Demonstrates custom validation preventing duplicate primary/secondary selections in the Django Admin interface. frontend_validation
API Form View - Verifies the DRF browsable API correctly renders the secondary practice area as a multi-select field. api_serializer_mu
API JSON Response - Confirms the DRF serializer successfully returns a `200 OK` and correctlyexposes the new many-to-many relationship as a list.* api_update_mu

@fyliu fyliu moved this to 👀PR being reviewed in P: PD: Project Board Jun 16, 2026
@fyliu fyliu self-requested a review June 16, 2026 23:53

@fyliu fyliu left a comment

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.

Thanks for getting this done so quickly and the great clarification questions!

Now that I'm reading the changes, I realized my last comment in slack about calling it practice_areas_secondary was confusing. I meant you should name the User model field practice_areas_secondary. You were correct before to name the relate_name "users_secondary". Can you change it back? Thanks!

@github-project-automation github-project-automation Bot moved this from 👀PR being reviewed to PR changes requested in P: PD: Project Board Jun 16, 2026
@egcuriel egcuriel requested a review from fyliu June 17, 2026 06:35
@fyliu fyliu moved this from PR changes requested to 👀PR being reviewed in P: PD: Project Board Jun 18, 2026

@fyliu fyliu left a comment

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.

Thanks!

Looks like there's a test failure. Maybe the it needed updating.

Details
django.db.utils.IntegrityError: duplicate key value violates unique constraint "uniq_global_user_check"
DETAIL:  Key (user_id, check_type_id)=(7ed5ee45-9d34-4091-bb8e-8cba1e28f02f, ed02c501-12cc-44b4-bf6c-40c846a5d9c1) already exists.
=========================== short test summary info ============================
FAILED core/tests/test_api.py::test_api_prevent_duplicate_global_usercheck - ...
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!! xdist.dsession.Interrupted: stopping after 1 failures !!!!!!!!!!!!!
======================== 1 failed, 42 passed in 21.59s =========================

@github-project-automation github-project-automation Bot moved this from 👀PR being reviewed to PR changes requested in P: PD: Project Board Jun 18, 2026
@fyliu

fyliu commented Jun 18, 2026

Copy link
Copy Markdown
Member

Nevermind the above comment. I ran update-requirements locally, and the newer version is what broke the test.

@egcuriel egcuriel left a comment

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.

  • Models: Implemented UserPracticeAreaSecondaryXref model to serve as a custom through-table, adding full_clean() validation to act as a database-level failsafe against duplicate primary/secondary practice area assignments.

  • Admin: Refined the ValidationError copy in admin.py to provide clear, actionable feedback to staff if they attempt to save conflicting data.

  • Naming Conventions: Updated the User model fields and related names to practice_areas_secondary and users_secondary per previous review feedback.

  • Verification: All automated tests are passing, and the integrity of the data is now protected at both the form and model layers

I went in to double check my code didn't break anything and realized a validation check in my model couldn't hurt the database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: PR changes requested

Development

Successfully merging this pull request may close these issues.

Create Table: UserPracticeAreaSecondaryXref

2 participants