#16176: Overwriting a property with field during model inheritance.
-------------------------------------+-------------------------------------
     Reporter:  czepiel.artur@…      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  1                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by metzlar@…):

 I made this work by defining the property dynamically inside the parent
 model definition:


 {{{
 class SomeTestModel(models.Model):
      some_field = models.CharField(max_length=100)

      class Meta:
          abstract = True

      @classmethod
      def __new__(cls, *args, **kwargs):
          inst = models.Model.__new__(cls, *args, **kwargs)
          if cls is SomeTestModel:
              inst.other_field = property(lambda x: "[OTHER] %s" %
 getattr(x, 'some_field'))
          return inst
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16176#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to