Django multi-table inheritance, how to know which is the child class of a model?

前端 未结 4 2130
梦毁少年i
梦毁少年i 2021-02-19 03:13

I\'m having a problem with multi-table inheritance in django.

Let’s make an example with bank accounts.

class account(models.Model):
    name = models……         


        
4条回答
  •  别那么骄傲
    2021-02-19 03:49

    You can use hasattr() method like:

    if hasattr(account, 'accounttypea'):
       account.accounttypea. = 
       do something here....
    
    elif hasattr(account, 'accounttypeb'):
       account.accounttypeb. = 
       do something here...
    

    It's not so DRY but works. :)

提交回复
热议问题