m0 seems to be undefined in the first condition, so you would probably have to move it inside.
Also, you are calling m0.named_modules(), while you should call it on the model.
After that m1 would be undefined, so you would have to add some more information what you are trying to do.
If you just want to access m0 and m1, which are names of two modules, you could use:
model.m0
model.m1