Bug fixes involving field names.
diff --git a/planetstack/apigen/api.template.py b/planetstack/apigen/api.template.py
index 5c5c914..c3e76e1 100644
--- a/planetstack/apigen/api.template.py
+++ b/planetstack/apigen/api.template.py
@@ -44,7 +44,7 @@
{% endfor %}
class Meta:
model = {{ object.camel }}
- fields = ({% for prop in object.props %}'{{ prop }}',{% endfor %}{% for ref in object.refs %}'{{ ref }}',{% endfor %})
+ fields = ({% for prop in object.props %}'{{ prop }}',{% endfor %}{% for ref in object.refs %}{%if ref.multi %}'{{ ref.plural }}'{% else %}'{{ ref }}'{% endif %},{% endfor %})
{% endfor %}
serializerLookUp = {
diff --git a/planetstack/apigen/modelgen b/planetstack/apigen/modelgen
index db9ae84..e75467e 100755
--- a/planetstack/apigen/modelgen
+++ b/planetstack/apigen/modelgen
@@ -43,13 +43,17 @@
self.model = m
self.props = []
self.refs = []
+ self.plural_name = None
def plural(self):
- name = str(self)
- if (name.endswith('s')):
- return name+'es'
+ if (self.plural_name):
+ return self.plural_name
else:
- return name+'s'
+ name = str(self)
+ if (name.endswith('s')):
+ return name+'es'
+ else:
+ return name+'s'
def camel(self):
name = str(self.model.__name__)
@@ -70,13 +74,19 @@
def compute_links(self):
for obj in self.values():
- #if (str(obj).lower()=='user'):
+ #if (str(obj)=='siteprivilege'):
# pdb.set_trace()
fields = obj.model._meta.fields
for f in fields:
if type(f)==ForeignKey and f.name in self.keys():
refobj = self[f.name]
obj.refs.append(refobj)
+ related_name = f.related_query_name()
+ if (related_name.lower()!=str(obj).lower()):
+ cobj = copy.deepcopy(obj)
+ cobj.multi = True
+ cobj.plural_name = related_name
+ refobj.refs.append(cobj)
else:
obj.props.append(f.name)
m2m = obj.model._meta.many_to_many
@@ -92,6 +102,14 @@
cobj = copy.deepcopy(obj)
cobj.multi=True
refobj.refs.append(cobj)
+
+ if (related_name.lower()!=str(obj).lower()):
+ cobj = copy.deepcopy(obj)
+ cobj.multi = True
+ cobj.plural_name = related_name
+ refobj.refs.append(obj)
+
+
def main():
diff --git a/planetstack/apigen/simple.template.txt b/planetstack/apigen/simple.template.txt
index 109927e..fb00670 100644
--- a/planetstack/apigen/simple.template.txt
+++ b/planetstack/apigen/simple.template.txt
@@ -1,7 +1,8 @@
{% for object in generator.all %}
Object {{ object }}:
Refs:
-{% for ref in object.refs %}{{ ref }}{% endfor %}
+{% for ref in object.refs %}
+{{ ref }}{% endfor %}
Props:
{% for prop in object.props %}{{ prop }}
{% endfor %}