Python_metaclasses
Metaclasses is a python concept which is said to be used only 2% of times. Meaning the usage is very rare. But the potential is vast. But here I’m specifying one area where the metalcasses is in action that you might have noticed but didn’t recongnized, which is Django / SQL Alchemy model defintion.
class Order(model.Model):
name = models.CharField()
amount = models.IntegerField()
...
Here it seems a normal class but despite declaring name as a model.CharField() or amount as models.IntegerField(). If you try to get the access the value of name or amount like this :
order = Order.object.last()
print(order.name)
print(order.amount)
You get the value from DB which corresponds to the field names. This is becuase metclasses remapped the instance attributes name & amount to those values.