-
Notifications
You must be signed in to change notification settings - Fork 4
/
BaseModel.tmpl
38 lines (33 loc) · 1.02 KB
/
BaseModel.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{% for model_item in models|dictsort %}
{% set model_name = model_item[0] %}
{% set model = model_item[1] %}
class Base{{ model.class_name }}(n.Netdot):
"""
{{ model.description|wordwrap(74,False,'\n ') }}
Attributes:
{% for f in model.fields %}
{{ f.name }}: {{ f.description }}
{% endfor %}
{% for link in reverse_links.get(model_name, []) %}
{{ link.method }}: List of {{ link.target }} objects
{% endfor %}
"""
resource = '{{ model.resource }}/'
id_field = '{{ model.id_field }}'
_fields = [
{% for f in model.fields %}
f.{{ f.class }}('{{ f.name }}'{{ f.args }}),
{% endfor %}
]
_views = {{ model.views }}
@property
def label(self):
l = ' '.join([str(getattr(self, l)) for l in {{ model.label }}])
return l.strip()
{% for link in reverse_links.get(model_name, []) %}
@property
def {{ link.method }}(self):
cls = getattr(pynetdot.models, '{{ link.target }}')
return cls.search({{ link.field }}=self.id)
{% endfor %}
{% endfor %}