Polymorphism in Django

前端 未结 8 907
死守一世寂寞
死守一世寂寞 2021-01-07 06:11

I have the following models. How do I get access to the unicode of the inheriting tables (Team and Athete) from the Entity table? I\'m trying to display a l

相关标签:
8条回答
  • 2021-01-07 07:09

    Loop over all the entities... if entity.class == 'Athlete' and entity.firstname and entity.lastname: blah

    Hope this helps.

    Edit: hmmm looks like I forgot about actually getting the combined list of both entities. Not sure I know of a slick way to do that.

    0 讨论(0)
  • 2021-01-07 07:11

    I am not very clear what you want to do, but in any case you can add a criteria in dervied class instead of checking unicode method of derived classes

    e.g. you can ask the class isTypeA ? or why don't you check the type?

    0 讨论(0)
提交回复
热议问题