diff --git a/bootstrap/webapp/view_models/Example.yaml_ b/bootstrap/webapp/view_models/Example.yaml_ index d6a8e43..acd28a0 100644 --- a/bootstrap/webapp/view_models/Example.yaml_ +++ b/bootstrap/webapp/view_models/Example.yaml_ @@ -15,15 +15,25 @@ access: show_in_nav: yes columns: - name: body|is_|_dt - type: boolean|integer|text|long_text|datetime|filename| + type: boolean|integer|text|long_text|datetime default: "{}" + - name: filesomething + type: file|audio|video|picture|image|img + accept: .doc,.docx # OPTIONAL: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept - name: related type: relationship # type relationship + to: other_model # OPTIONAL: otherwise we get it from the name + backref: backref_model # OPTIONAL: name of the backref model, otherwise from name + foreign_key: fk_1 # OPTIONAL: MUST do it, if several related to the same column multiple: true # could be many-to-many - name: choisy type: choice choices: INT_INFO: int_info # key:value +backrefs: + - name: related_to + model: song # list of backrefs that should be displayed + resolve: '.song_to' # OPTIONAL: in case it's a additional table that needs to be resolved further display: primary: type secondary: text diff --git a/oshipka.sh b/oshipka.sh index 696cb1f..e412212 100755 --- a/oshipka.sh +++ b/oshipka.sh @@ -283,7 +283,7 @@ db_upgrade() { db_purge_recreate() { shift source venv/bin/activate - rm -rf data/db.sqlite data/search_index migrations/ + rm -rf data/db.sqlite data/search_index migrations/ data/media python manager.py db init db_migrate db_upgrade diff --git a/vm_gen/templates/_relationship_py b/vm_gen/templates/_relationship_py index 8dac0ae..eb9f1d5 100644 --- a/vm_gen/templates/_relationship_py +++ b/vm_gen/templates/_relationship_py @@ -2,10 +2,10 @@ [%- if not column.multiple %] [[ column.name ]]_id = db.Column(db.Integer, db.ForeignKey('[%- if column.to %][[ column.to|camel_to_snake ]][%- else %][[ column.name ]][% endif %].id')) [%- endif %] - [[ column.name|pluralize if column.multiple else column.name ]] = db.relationship('[%- if column.to %][[ column.to ]][%- else %][[ column.name|snake_to_camel ]][% endif %]', + [[ column.name|pluralize if column.multiple else column.name ]] = db.relationship('[%- if column.to %][[ column.to|snake_to_camel ]][%- else %][[ column.name|snake_to_camel ]][% endif %]', [%- if column.multiple %]secondary=[[ column.secondary.name ]], [%- endif %] backref=db.backref("[%- if column.backref %][[ column.backref ]][%- else %][[ name|camel_to_snake|pluralize ]][%- endif %]"), - [%- if column.foreign_keys %]foreign_keys=[ [[ column.foreign_keys ]]_id],[%- endif %] + [%- if column.foreign_key %]foreign_keys=[ [[ column.foreign_key ]]_id],[%- endif %] ) [%- if column.multiple %] diff --git a/vm_gen/templates/html/_create.html b/vm_gen/templates/html/_create.html index 828dd24..817b8e9 100644 --- a/vm_gen/templates/html/_create.html +++ b/vm_gen/templates/html/_create.html @@ -18,7 +18,7 @@ {% if [[ column.name|pluralize ]] is not defined and instance and instance.[[ column.name|pluralize ]] is defined %} {% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %} {% else %} - {% set [[ column.name|pluralize ]] = model_views.[[ column.name ]].model.query.all() %} + {% set [[ column.name|pluralize ]] = model_views.[[ column.to or column.name ]].model.query.all() %} {% endif %} {%- for sub_instance in [[ column.name|pluralize ]] %} diff --git a/vm_gen/templates/html/_get.html b/vm_gen/templates/html/_get.html index 0494b2f..1758046 100644 --- a/vm_gen/templates/html/_get.html +++ b/vm_gen/templates/html/_get.html @@ -1,6 +1,13 @@ [%- for column in columns %] {% if "[[ column.name ]]" not in skip_list %} -
  • {{ _("[[ column.name ]]") }}: +
  • [%- if column.type in ['relationship'] and column.multiple %]{{ _("[[ column.name|pluralize ]]") }}[%- else %]{{ _("[[ column.name ]]") }}[%- endif %]: + [%- if not column.type in ['bool', 'boolean', ] %] + [%- if column.type in ['relationship'] and column.multiple %] + {% if not instance.[[ column.name|pluralize ]] %}{% else %} + [%- else %] + {% if not instance.[[ column.name ]] %}{% else %} + [%- endif %] + [%- endif %] [%- if column.type in ['picture', 'image', 'img'] %] [%- elif column.type in ['video'] %] @@ -12,7 +19,11 @@ [%- elif column.type in ['relationship'] %] [%- if column.multiple %] - {{ instance.[[ column.name|pluralize ]] }} +
      + {% for instance in instance.[[ column.name|pluralize ]] %} + {% include "[[ column.name|camel_to_snake ]]/_list_item.html" %} + {% endfor %} +
    [%- else %] {{ instance.[[ column.name ]] }} [%- endif %] @@ -23,4 +34,21 @@ [%- endif %]
  • {% endif %} +[%- if not column.type in ['bool', 'boolean', ] %] +{% endif %} +[%- endif %] +[%- endfor %] +[%- for backref in backrefs %] +
  • {{ _("[[ backref.name ]]") }}: +
      +{% set ex_instance = instance %} +{% for tmp_instance in ex_instance.[[ backref.name ]] %} + [%- if backref.resolve %] + {% set instance = tmp_instance[[ backref.resolve ]] %} + [%- else %] + {% set instance = tmp_instance %} + [%- endif %] +{% include "[[ backref.model ]]/_list_item.html" %} +{% endfor %} +
    [%- endfor %] \ No newline at end of file diff --git a/vm_gen/templates/html/_update.html b/vm_gen/templates/html/_update.html index cbfd0a5..06c55b7 100644 --- a/vm_gen/templates/html/_update.html +++ b/vm_gen/templates/html/_update.html @@ -13,7 +13,7 @@ [%- else %]