Hello all,

I'm currently using a mixin class to contribute a few extra fields to
my models, to keep track of some metadata on instances (for example,
an update_mode attribute that specifies whether data should replace
all fields or only non-empty ones in the database when the instance is
saved).

Because of the way inheritance works, I end up having to define
__init__ in each model and call the __init__ methods of my mixin class
and the Django Model class within it, like so:

class Mixin(object):
    def __init__(self):
         self.update_mode = 'replace'
         # ...

class Contact(Mixin, models.Model):
    def __init__(self, *args, **kwargs):
          super(Mixin, self).__init__()
          super(models.Model, self).__init__(*args, **kwargs)
    # ... and similarly for other models

I do need the extra properties to be specified in Mixin.__init__ so
that every new instance gets some initial values.

My question is mostly about style: is this the best way to go about
doing things?  Is there a more 'Djangonic' (and consistently D.R.Y.)
way of tacking this extra information onto my model instances?  Is
anything about this approach likely to break Django's current or
future behavior with models?  All opinions are welcome.

Thanks,
Richard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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 this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to