[ADD] DYNAMIC FIELDS: Add new app - dynamic fields

This commit is contained in:
Horilla
2025-01-06 16:22:16 +05:30
parent 6b2ccf66ab
commit d6ab7f5d74
23 changed files with 1004 additions and 0 deletions

35
dynamic_fields/methods.py Normal file
View File

@@ -0,0 +1,35 @@
"""
dynamic_fields/methods.py
"""
from django.db import connection
from django.template.loader import render_to_string
from horilla.horilla_middlewares import _thread_locals
def column_exists(table_name, column_name):
"""
Check if the column exists in the database table.
"""
with connection.cursor() as cursor:
columns = [
col[0]
for col in connection.introspection.get_table_description(
cursor, table_name
)
]
return column_name in columns
def structured(self):
"""
Render the form fields as HTML table rows with Bootstrap styling.
"""
request = getattr(_thread_locals, "request", None)
context = {
"form": self,
"request": request,
}
table_html = render_to_string("dynamic_fields/common/form.html", context)
return table_html