CORD-1594: Tag models with information about the leaf model, for casting
generic instances into specialized ones
Change-Id: I7b0f283b11380363742a284dc794bf3914e81fc9
diff --git a/lib/xos-genx/xosgenx/targets/django-split.xtarget b/lib/xos-genx/xosgenx/targets/django-split.xtarget
index a6ccab5..5260e85 100644
--- a/lib/xos-genx/xosgenx/targets/django-split.xtarget
+++ b/lib/xos-genx/xosgenx/targets/django-split.xtarget
@@ -45,6 +45,9 @@
# Generated methods
def save(self, *args, **kwds):
+ if not self.leaf_model_name:
+ self.leaf_model_name = "{{ m.name }}"
+
try:
self.__xos_save_base(*args, **kwds)
except AttributeError:
diff --git a/lib/xos-genx/xosgenx/targets/django.xtarget b/lib/xos-genx/xosgenx/targets/django.xtarget
index 400596c..e9a56ec 100644
--- a/lib/xos-genx/xosgenx/targets/django.xtarget
+++ b/lib/xos-genx/xosgenx/targets/django.xtarget
@@ -45,6 +45,9 @@
{% if m.name!='XOSBase' and 'Mixin' not in m.name %}
# Generated methods
def save(self, *args, **kwds):
+ if not self.leaf_model_name:
+ self.leaf_model_name = "{{ m.name }}"
+
try:
self.__xos_save_base(*args, **kwds)
except AttributeError:
diff --git a/lib/xos-genx/xosgenx/targets/service.xtarget b/lib/xos-genx/xosgenx/targets/service.xtarget
index a48abb7..80d90d6 100644
--- a/lib/xos-genx/xosgenx/targets/service.xtarget
+++ b/lib/xos-genx/xosgenx/targets/service.xtarget
@@ -61,6 +61,9 @@
# Generated methods
def save(self, *args, **kwds):
+ if not self.leaf_model_name:
+ self.leaf_model_name = "{{ m.name }}"
+
try:
self.__xos_save_base(*args, **kwds)
except AttributeError:
diff --git a/xos/core/models/core.xproto b/xos/core/models/core.xproto
index 44dc67c..fd23912 100644
--- a/xos/core/models/core.xproto
+++ b/xos/core/models/core.xproto
@@ -17,6 +17,7 @@
required bool no_sync = 12 [default = False];
required bool no_policy = 13 [default = False];
optional string policy_status = 14 [default = "0 - Policy in process", max_length = 1024];
+ required string leaf_model_name = 15 [null = False, max_length = 1024, help_text = "The most specialized model in this chain of inheritance, often defined by a service developer"];
}
message User (AbstractBaseUser,PlModelMixIn) {