Skip to main content

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_list to find the best matching subfield.
  • If a ManyToMany field is in field_list:

    • All of its fields are extracted except those listed in ignore_m2m_fields.

📤 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nyz_dynamic_design_builder-0.2.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyz_dynamic_design_builder-0.2.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file nyz_dynamic_design_builder-0.2.0.tar.gz.

File metadata

File hashes

Hashes for nyz_dynamic_design_builder-0.2.0.tar.gz
Algorithm Hash digest
SHA256 548e0a3413e0a7162e4ff93bd73d37b62be687b85b350773b5fc027b25f42aef
MD5 8e97f9ad515eca1194993a65b7eea12d
BLAKE2b-256 538f5e1a5a7676ad203014cef567316c16a9bde53507bc98b81101a189645271

See more details on using hashes here.

File details

Details for the file nyz_dynamic_design_builder-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nyz_dynamic_design_builder-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b725fc74d6ba97fcf3aef3664633759495dec04c63cd77134926d3385a7b9c09
MD5 bfe508ded1f9c0fe7bc63289d8a4fdea
BLAKE2b-256 6a8abd6bb94b00eb05ee1fd8de3e3dcfe9b839c06cd73c072956dc1a498f46d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page