Dynamic Excel export builder for Django ORM querysets
Project description
🧩 nyz-dynamic-design-builder
nyz-dynamic-design-builder is a lightweight Django-compatible Python utility for exporting model data (including ForeignKey and ManyToMany fields) to Excel — no pandas required.
📦 Installation
pip install nyz-dynamic-design-builder
📝 Sample Model: Blog
Assume you have a Blog model like this:
from django.db import models
from django.contrib.auth import get_user_model
User = get_user_model()
class Blog(models.Model):
title = models.CharField(max_length=255)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
tags = models.ManyToManyField("Tag", blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Tag(models.Model):
name = models.CharField(max_length=100)
⚙️ Usage
from nyz_dynamic_design_builder.exporter import export_model_to_excel
export_model_to_excel(
file_path="blog_export.xlsx",
model=Blog,
field_list=["title", "content", "author", "tags", "created_at"],
search_fk_list=["text", "name", "username", "first_name", "last_name"],
special_fk_values={"author": ["username", "first_name", "last_name", "is_active"]},
ignore_m2m_fields=["id", "created_at", "updated_at"]
)
🔍 Parameters Explained
| Parameter | Description |
|---|---|
file_path |
Path to save the exported Excel file. |
model |
Django model class to export from. |
field_list |
Fields to export from the model (includes FK and M2M fields as needed). |
search_fk_list |
For FK fields in field_list, this defines the inner field search priority (e.g. text, name). |
special_fk_values |
If a field in field_list is also in special_fk_values, it will extract only the listed fields. |
ignore_m2m_fields |
If a field in field_list is M2M, this list is used to ignore specific subfields. |
🧠 Logic
-
If a ForeignKey field is included in
field_list:- First it checks if the field is listed in
special_fk_values. If so, it extracts only those subfields. - Otherwise, it loops through
search_fk_listto find the best matching subfield.
- First it checks if the field is listed in
-
If a ManyToMany field is in
field_list:- All of its fields are extracted except those listed in
ignore_m2m_fields.
- All of its fields are extracted except those listed in
📤 Output Example
Excel file might include columns like:
- Title
- Content
- Author - Username
- Author - First Name
- Author - Last Name
- Author - Is Active
- Tags 1 - Name
- Tags 2 - Name
- Created At
✅ Perfect For
- Admin Excel exports
- Lightweight dynamic field selection
- Human-readable relationship data without pandas
🔒 Notes
- No need to modify your model.
- Works with any Django model, respects relationships.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nyz_dynamic_design_builder-0.1.1.tar.gz.
File metadata
- Download URL: nyz_dynamic_design_builder-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8578af866cd6c8346bf4535ef952c18fc8dcc0c42056eeb20365bbf4f97f1b8
|
|
| MD5 |
864e9d65277d1cb22a34fc4d9e6e1c93
|
|
| BLAKE2b-256 |
6a9439eb49f6f70d47451cdf87e61fcceabc0ec088306243768df4a520c87a46
|
File details
Details for the file nyz_dynamic_design_builder-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nyz_dynamic_design_builder-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4c050ed1737b514985ba1d75725e3ff0df298d113864d2bd127428d1f60ac8e
|
|
| MD5 |
7b1211ec890081b14250813240d03d96
|
|
| BLAKE2b-256 |
edfafbb5bebffd9d4423265762a3400b2c21d2f240974e3f0330bf7bf9d3fdfa
|