Skip to content

Commit

Permalink
Fix Parent module import and htmx urls (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcardle authored Mar 19, 2023
1 parent 52f36e0 commit 952436e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/django/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ CHANNEL_LAYERS = {
htmx_body += `
<div class="col col-lg-6">
<h5>Add A ${model.name}</h5>
<div hx-get="{% url 'app_${model.name}_htmx_create' %}" hx-trigger="load" hx-swap="outerHTML"></div>
<div hx-get="{% url '${app.name}_${model.name}_htmx_create' %}" hx-trigger="load" hx-swap="outerHTML"></div>
<h4>${model.name} List</h4>
<div hx-get="{% url 'app_${model.name}_htmx_list' %}" hx-trigger="load">
<div hx-get="{% url '${app.name}_${model.name}_htmx_list' %}" hx-trigger="load">
</div>
</div>`
})
Expand Down Expand Up @@ -1060,6 +1060,8 @@ CHANNEL_LAYERS = {
var imports = 'from django.db import models\n'
imports += 'from django.urls import reverse\n'

const parentImportClasses = new Set();

let importGIS = false;
let importPostgres = false;

Expand All @@ -1074,7 +1076,8 @@ CHANNEL_LAYERS = {
const model = this.store.getters.modelData(parent.model)
return model.name
} else if (parent.type == 'django') {
return parent.class.split(".").pop()
parentImportClasses.add(parent.class);
return parent.class.split(".").pop();
}
}))

Expand Down Expand Up @@ -1163,6 +1166,12 @@ CHANNEL_LAYERS = {
}

})

parentImportClasses.forEach((parent) => {
const parentSplit = parent.split(".");
const parentModule = parentSplit.pop();
imports += 'from ' + parentSplit.join('.') + " import " + parentModule + "\n";
})

if (importGIS) {
imports += 'from django.contrib.gis.db import models as gis_models\n'
Expand Down

0 comments on commit 952436e

Please sign in to comment.