oshipka/vm_gen/templates/_model_py
Daniel Tsvetkov bad151eb43 acls
2021-05-08 20:53:50 +02:00

38 lines
1.3 KiB
Plaintext

[%- if _choice_types %]
from sqlalchemy_utils import ChoiceType
[%- endif %]
class [[ name ]](db.Model, ModelController[% for inherit in interits %], [[ inherit ]][% endfor %]):
[%- include "_model_choice_header_py" %]
[%- include "_model_searchable_header_py" %]
_file_columns = [ [%- for column in columns %][%- if column.is_file %]"[[ column.name ]]", [%- endif %] [%- endfor %] ]
model_acls = [[ acls ]]
[% for column in columns %]
[%- if column._type == 'relationship' %]
[%- include "_relationship_py" %]
[%- else %]
[[ column.name ]] = db.Column([[ column._type ]],
[%- if column.default %]default="[[ column.default ]]",[%- endif %]
[%- if column.index %]index=True,[%- endif %])
[%- endif %]
[%- endfor %]
[%- if extra_code %]
[[ extra_code ]]
[%- endif %]
[%- if display %]
def __repr__(self):
[%- if display.tertiary %]
return "{} ({} - {})".format(self.[[ display.primary ]], self.[[ display.secondary ]], self.[[ display.tertiary]])
[%- elif display.secondary %]
return "{} ({})".format(self.[[ display.primary ]], self.[[ display.secondary ]])
[%- else %]
return "{}".format(self.[[ display.primary ]])
[%- endif %]
[%- endif %]