oshipka/vm_gen/templates/_model_py

57 lines
1.8 KiB
Plaintext
Raw Normal View History

2020-06-04 15:24:18 +02:00
[%- if _choice_types %]
from sqlalchemy_utils import ChoiceType
[%- endif %]
2021-05-09 13:43:51 +02:00
[%- if _password_types %]
from werkzeug.security import generate_password_hash
[%- endif %]
2021-05-09 14:44:11 +02:00
[% for inherit_import in inherits_imports %]
[[ inherit_import ]]
[% endfor %]
class [[ name ]](db.Model, ModelController[% for inherit in inherits %], [[ inherit ]][% endfor %]):
2020-06-04 15:24:18 +02:00
[%- include "_model_choice_header_py" %]
[%- include "_model_searchable_header_py" %]
2021-05-08 15:52:52 +02:00
_file_columns = [ [%- for column in columns %][%- if column.is_file %]"[[ column.name ]]", [%- endif %] [%- endfor %] ]
2021-05-08 12:24:13 +02:00
2021-05-08 20:53:50 +02:00
model_acls = [[ acls ]]
[% for column in columns %]
2020-06-04 15:24:18 +02:00
[%- 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 %])
2021-05-09 13:43:51 +02:00
[%- if column.type == 'password' %]
@property
def [[ column.name ]]__password(self):
raise AttributeError('password is not a readable attribute')
@[[ column.name ]]__password.setter
def [[ column.name ]]__password(self, password):
self.password_hash = generate_password_hash(password)
[% endif %]
2020-06-04 15:24:18 +02:00
[%- endif %]
[%- endfor %]
[%- if extra_code %]
[[ extra_code ]]
[%- endif %]
2020-08-11 19:02:29 +02:00
[%- 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 %]