Prevent race condition when creating image Filter objects with get_or_create - fixes #312

NB this fix is based on master, and will need to be cherry-picked when merging into stable/0.8.x