For most people, the best way to prevent this sort of fainting, is to not lock your knees back. Generally people unacustomed to long periods of standing will lock their knees. It takes less effort to stand in this manner, unfortunately it cuts off return circulation of your blood from your feet. Wiggling your toes will certainly help, but straightening your knees will go a lot longer towards helping you maintain consiousness.
There are a few people who don't have this problem. I am one of those people. My knees lock straight back and my circulation is not affected. This aided me well in my military career as I could stand at attention for many hours without moving.
It turns out that I can only perform this action because my knees don't fit together properly. Either by abuse or birth I have a wide range of lateral motion in both knees and my patella tends to occasionally not move properly. So, I have been gifted with the ability to stand for long periods of time, and the Army gave me a big fat check to go away.
On the down side, I can barely run anymore, I can't sit for too long, and two flights of stairs will make me tell you all my secrets.