Django Proxy Inheritance

Proxy Inheritance This style is used if you only want to change the behavior of the model at the python level without changing the fields of the model. You inherit from the base class and can add your own properties other than fields. The base class must not be an abstract class. We cannot use multiple inheritance in proxy models. The main use is to overwrite the main features of an existing model.

from django.db import models

# create your models here.

class person(models.model):
    first_name = models.charfield(max_length=30)
    last_name = models.charfield(max_length=30)

class myperson(person):
    class meta:
        proxy=true

    def fullname(self):
        return self.first_name ++ self.last_name

The myperson class operates on the same database table as its parent person class. In particular, any new instances of person will also be available through myperson, and vice versa:


from myapp.models import person, myperson

p = person(first_name = anton, last_name = anton)

p.save()
With the data added, we can now access first_name and last_name using the fullname() 
method of the myperson class.

myperson = myperson.objects.all()0

myperson.fullname()