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 — into a structured pandas.DataFrame format. You can write it to Excel if needed.
No serializers or admin customization required. Just your model and your queryset.
📦 Installation
pip install nyz-dynamic-design-builder
📝 Sample Model: Blog
from django.db import models
from django.contrib.auth import get_user_model
User = get_user_model()
class Tag(models.Model):
name = models.CharField(max_length=100)
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)
⚙️ Usage
from nyz_dynamic_design_builder.exporter import export_data
queryset = Blog.objects.all()
df = export_data(
query=queryset,
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"]
},
special_m2m_fields={
"tags": ["name"]
},
ignore_m2m_fields=["id", "created_at", "updated_at"]
)
df.to_excel("blog_export.xlsx", index=False)
🔍 Parameters Explained
| Parameter | Description |
|---|---|
query |
Django queryset (e.g. Blog.objects.all()) |
field_list |
Fields to export from the model (including FK/M2M) |
search_fk_list |
List of attributes to try in FK fields (fallback order) |
special_fk_values |
Dict: FK field -> list of subfields to extract |
special_m2m_fields |
Dict: M2M field -> list of subfields to extract |
ignore_m2m_fields |
M2M fields or subfields to ignore |
🧠 How It Works
-
For
ForeignKeyfields:- If listed in
special_fk_values, it exports the specified subfields. - Else, it searches through
search_fk_listand uses the first match.
- If listed in
-
For
ManyToManyfields:- If listed in
special_m2m_fields, only those subfields are exported. - Otherwise, all subfields are exported except those in
ignore_m2m_fields.
- If listed in
📤 Output Example
Columns in the Excel might look like:
TitleContentAuthor - UsernameAuthor - First NameAuthor - Last NameAuthor - Is ActiveTags 1 - NameTags 2 - NameCreated At
✅ Perfect For
- Admin-level or reporting exports
- Human-readable outputs for nested fields
- Avoiding verbose serializers or views for temporary data output
- Excel generation from any model dynamically
🔒 Notes
- You control exactly which fields and subfields are included.
pandasandopenpyxlare required.- You can use
.to_excel(),.to_csv()or any otherpandasmethod after export.
📜 License
MIT
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-2.0.0.tar.gz.
File metadata
- Download URL: nyz_dynamic_design_builder-2.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb715bec7233a9f5816ad0777a6e1e3ff593644cf80486353fde74a24f55377f
|
|
| MD5 |
ca9b4d54cb8a9e4d0f94166da1f1c8fa
|
|
| BLAKE2b-256 |
de88a2caf02f4915dea6f463e0bc59cf2831c4bdb0fe129faa13888a9b3da2da
|
File details
Details for the file nyz_dynamic_design_builder-2.0.0-py3-none-any.whl.
File metadata
- Download URL: nyz_dynamic_design_builder-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 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 |
27b60b4c2f3b73fed31bace28272999ae380ca56f73e77aa0c470e904209e84c
|
|
| MD5 |
681a17c20a28aeeb607fb15c1e745e4e
|
|
| BLAKE2b-256 |
6f4932f97849ea13a903bf939c7d6f6b10a73462276a42325629405041185a8f
|