-
Notifications
You must be signed in to change notification settings - Fork 32
Keeping Django models in sync with OSPC model parameters
This document gives a guide on how to update the Django models for this application.
In Tax-Calculator, certain JSON files contain parameters that the user can adjust for a microsimulation. Similarly, in OGUSA simulations, the OGUSA package has a set number of parameters that the user can adjust for a simulation. We maintain a corresponding Django model to keep track of these choices. The mapping of package-level parameters to Django models is as follows:
OGUSA parameters => DynamicSaveInputs
Behavior.json => DynamicBehaviorSaveInputs
Current_law_policy.json, growth.json => TaxSaveInputs
When any of the parameters in the packages change, the corresponding models must be updated. The possible changes and corresponding actions are:
Removal of a parameter: Nothing bad will happen here if you don’t remove the corresponding attribute from the model. However, for good housekeeping, since the parameter is no longer used, it’s advisable to delete it from the model
Addition of a parameter: You will get an error when attempting to save a new instance of the Django model if you do not add a corresponding attribute to the model. This makes it hard to miss new parameters, since you can’t do a real TaxBrain run until there is an attribute on the TaxSaveInputs model that matches a parameter from taxcalc
Renaming of a parameter:
If you see that a parameter has been renamed, rename it in a corresponding fashion in the model. When you execute python manage.py makemigrations
, Django will attempt to figure out which parameter(s) have been renamed (and then ask you to confirm that parameter X has been renamed to Y). It is advisable to manually investigate the generated migration file and make sure that the proper renaming has happened prior to executing python manage.py migrate
There is nothing special about the above - just standard Django migrations. However, the number of parameters in OSPC models can make changes a bit daunting. And always remeber to check in your migration changes with your pull requests!!!