Created
December 15, 2011 13:30
-
-
Save arruda/1481088 to your computer and use it in GitHub Desktop.
Django - Herança, Modelos Abstratos e OO Na Veia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C(models.Model): | |
nome = models.CharField(u"Nome", max_length=250) | |
class Meta: | |
abstract = True | |
class A(C): | |
atributo_a = models.CharField(u"Atributo de A", max_length=250) | |
class B(C): | |
atributo_b = models.CharField(u"Atributo de B", max_length=250) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class F(models.Model): | |
chave_f = models.ForeignKey('nomeApp.D') | |
class Meta: | |
abstract = True | |
class C(models.Model): | |
name = models.CharField(u"Nome", max_length=250) | |
class Meta: | |
abstract = True | |
class A(C, F): | |
atributo_a = models.CharField(u"Atributo de A", max_length=250) | |
class B(C, F): | |
atributo_b = models.CharField(u"Atributo de B", max_length=250) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class F(models.Model): | |
chave_f = models.ForeignKey('nomeApp.D',related_name='meus_%(class)ss') | |
class Meta: | |
abstract = True | |
class C(models.Model): | |
name = models.CharField(u"Nome", max_length=250) | |
class Meta: | |
abstract = True | |
class A(C, F): | |
atributo_a = models.CharField(u"Atributo de A", max_length=250) | |
class B(C, F): | |
atributo_b = models.CharField(u"Atributo de B", max_length=250) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C(models.Model): | |
nome = models.CharField(u"Nome", max_length=250) | |
class A(C): | |
atributo_a = models.CharField(u"Atributo de A", max_length=250) | |
class B(C): | |
atributo_b = models.CharField(u"Atributo de B", max_length=250) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A(C): | |
nome = models.CharField(u"Nome", max_length=250) | |
atributo_a = models.CharField(u"Atributo de A", max_length=250) | |
class B(C): | |
nome = models.CharField(u"Nome", max_length=250) | |
atributo_b = models.CharField(u"Atributo de B", max_length=250) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment