use same code in model metaclasses