4.0 KiB
4.0 KiB
OT Forms Field Mismatch Fixes
Summary
Fixed multiple field name mismatches between ot/models.py and ot/forms.py that were causing Django FieldError exceptions.
Date
October 13, 2025
Issues Found and Fixed
1. OTConsultForm
Issues:
- Form used
reasons_for_referralbut model hasreasons - Form used
recommendation_typebut model hasrecommendation - Form used
recommendationsbut model hasrecommendation_notes - Form used
behavior_descriptorsbut model hasinfant_behavior_descriptorsandcurrent_behavior_descriptors(two separate fields)
Fixes Applied:
- ✅ Changed
reasons_for_referral→reasonsin Meta.fields - ✅ Changed
recommendation_type→recommendationin Meta.fields - ✅ Changed
recommendations→recommendation_notesin Meta.fields - ✅ Split
behavior_descriptors→infant_behavior_descriptorsandcurrent_behavior_descriptorsin Meta.fields - ✅ Updated widgets to include
recommendation_notesinstead ofrecommendations - ✅ Updated HTML layout to use correct field names in textarea elements
- ✅ Updated Recommendations fieldset to use
recommendationandrecommendation_notes
2. OTSessionForm
Issues:
- Form included
session_timefield but model doesn't have this field (OTSession only hassession_date)
Fixes Applied:
- ✅ Removed
session_timefrom Meta.fields - ✅ Removed
session_timewidget - ✅ Updated layout to remove
session_timecolumn (changed from 3-column to 2-column layout)
3. OTTargetSkillForm
Issues:
- Form used
baseline_scoreandcurrent_scorebut model only hasscorefield - Form was missing
orderfield that exists in model
Fixes Applied:
- ✅ Changed
baseline_scoreandcurrent_score→scorein Meta.fields - ✅ Added
orderfield to Meta.fields with HiddenInput widget - ✅ Updated clean() method to validate single
scorefield instead of two separate fields
4. OTProgressReportForm
Issues:
- Form used
goals_achievedbut model hasgoals_progress(JSONField) - Form was missing
sessions_scheduledfield - Form was missing
continue_treatmentfield
Fixes Applied:
- ✅ Changed
goals_achieved→goals_progressin Meta.fields - ✅ Added
sessions_scheduledfield to Meta.fields - ✅ Added
continue_treatmentfield to Meta.fields - ✅ Removed
goals_achievedwidget - ✅ Updated layout to include Session Summary fieldset with both scheduled and attended sessions
- ✅ Added HTML textarea for
goals_progressJSONField with proper placeholder - ✅ Added
continue_treatmentcheckbox to Recommendations fieldset
Model Field Reference
OTConsult Model Fields:
- patient, appointment, consultation_date, provider
- reasons (JSONField)
- top_difficulty_areas (JSONField)
- developmental_motor_milestones (JSONField)
- self_help_skills (JSONField)
- feeding_participation (TextField)
- infant_behavior_descriptors (JSONField)
- current_behavior_descriptors (JSONField)
- recommendation (CharField with choices)
- recommendation_notes (TextField)
OTSession Model Fields:
- patient, appointment, session_date, provider
- session_type, cooperative_level, distraction_tolerance
- activities_checklist (JSONField)
- observations, activities_performed, recommendations
OTTargetSkill Model Fields:
- session, skill_name, score, notes, order
OTProgressReport Model Fields:
- patient, report_date, provider
- sessions_scheduled, sessions_attended
- goals_progress (JSONField)
- overall_progress, recommendations, continue_treatment
Testing Recommendations
- Test OTConsultForm creation with all fields
- Test OTSessionForm with target skills formset
- Test OTTargetSkillForm score validation (0-10 range)
- Test OTProgressReportForm with JSONField for goals_progress
- Verify all form submissions work without FieldError exceptions
Files Modified
ot/forms.py- All form classes updated to match model fields
Status
✅ All field mismatches resolved ✅ Forms now match model definitions exactly ✅ Ready for testing