Inheritance of the multiple Django model, django-push notifications

I am writing a back end for a mobile application using Django 1.8. django-push-notificationslib provides a model GCMDevice. The problem is that I already have a model Devicewith some required field and some logic that I do not want to lose.

What I wanted to do was inherit entire functions GCMDeviceand configure them on my device model (which btw inherits another mixin that provides spatial data fields, with a custom set of object manager that I want to save). I read about 3 different ideas for django model inheritance, but none of them seemed to solve my problem (supporting managers, providing functionality django-push-notifications, keeping my model fields Device). Maybe OneToOne will do the job?

IDEA:

class Device(MyMixin):
    gcm_device = models.OneToOneField(GCMDevice)
    my_other_field = models.TextField()

    def send_message(self, payload):
        self.gcm_device.send_message(payload)
+4
source share
1 answer

Any reason to inherit? Can a composition be a substitute for what you are trying to do as a heir?

----------------- Edited answer -----------------

class Device(models.Model):
    ...
    gcm_device = models.OneToOneField(GCMDevice)

I gave the simplest case, you could make the GCM device your primary key.

+1
source

All Articles