[Python] Django - override base class model field on get

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Django1.6

    i have abstract class A, and class B:

    class A(Model):
    att = CharField()

    class Meta:
    abstract = True

    class B(A):
    pass


    i want to override the behaviour of 'att' (without touching class A): so when using:

    b = B(att='a').save()
    b.att (output is 'a')


    but i want to override the output: so:

    b.att (output is something else like 'a_thanks')

    class B(A):
    @propert
    def att(self):
    return self._att + '_thanks'


    how can i do it? i know this is possible from django 1.10

    Continue reading...

Compartilhe esta Página