Not obvious to me how the logic on this line works from a glance.  Perhaps break it out.
Also `model_class` might be a better name.