Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Parent module import and htmx urls #181

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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