CORD-2990 add uniqueness constraints for names in the core;
pass unique keyword through to django;
support unique_with in services
Change-Id: I33e9f6b2504b5029fa75dad8251a56e2c8e364c2
diff --git a/lib/xos-genx/xosgenx/jinja2_extensions/django.py b/lib/xos-genx/xosgenx/jinja2_extensions/django.py
index 2632c00..464172a 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions/django.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions/django.py
@@ -79,7 +79,7 @@
return 'GenericRelation'
def map_xproto_to_django(f):
- allowed_keys=['help_text','default','max_length','modifier','blank','choices','db_index','null','editable','on_delete','verbose_name', 'auto_now_add']
+ allowed_keys=['help_text','default','max_length','modifier','blank','choices','db_index','null','editable','on_delete','verbose_name', 'auto_now_add', 'unique']
m = {'modifier':{'optional':True, 'required':False, '_target':'null'}}
out = {}
diff --git a/lib/xos-genx/xosgenx/targets/service.xtarget b/lib/xos-genx/xosgenx/targets/service.xtarget
index ed78ff1..7b40110 100644
--- a/lib/xos-genx/xosgenx/targets/service.xtarget
+++ b/lib/xos-genx/xosgenx/targets/service.xtarget
@@ -56,6 +56,10 @@
app_label = {{ xproto_first_non_empty([m.options.app_label, options.app_label, options.name, "Set an app label in your xproto!"]) | lower}}
# name = {{ xproto_first_non_empty([m.options.name, options.name, "Set a name in your xproto!"]) }}
verbose_name = "{{ xproto_unquote(xproto_first_non_empty([m.options.verbose_name, m.name])) }}"
+ {%- set uniques = xproto_field_graph_components(m.fields) %}
+ {%- if uniques %}
+ unique_together = {{ xproto_tuplify(uniques) }}
+ {%- endif %}
# Primitive Fields (Not Relations)
{% for f in m.fields %}