The problem here is that you need to call the method save for both objects before adding the template to the product:
template.save()
plan.save()
plan.templates.add(template)
Django can’t add it if none of those objects has an id (plan and template)