I think this is great. Traditionally I always used messages like
Fixed #25. Users can now enter their email addresses.
assuming the entire fix was in one commit. I chose this because Django
uses the same style, and there are some plugins for trac which will
automatically close a ticket if you format it that way in the commit
message. If a commit relates to a ticket but does not close it, I think
the method you propose works great.
One thing we may wish to do is instead use [#NNN] or [ticket:NNN] in the
commit message. This way, you will be able to click on the number any
time the commit message is listed in trac, e.g. at
https://code.ductus.us/timeline