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 — 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 ForeignKey fields:

    • If listed in special_fk_values, it exports the specified subfields.
    • Else, it searches through search_fk_list and uses the first match.
  • For ManyToMany fields:

    • If listed in special_m2m_fields, only those subfields are exported.
    • Otherwise, all subfields are exported except those in ignore_m2m_fields.

📤 Output Example

Columns in the Excel might look 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-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.
  • pandas and openpyxl are required.
  • You can use .to_excel(), .to_csv() or any other pandas method after export.

📜 License

MIT

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-1.0.0.tar.gz (4.7 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-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for nyz_dynamic_design_builder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d810c7481c2ae3ec9e73a6f76e8485e4e4f1b26fe1e4673484827327fda44e5d
MD5 dcc6bd639b0c0b4b983b435dc738d6e0
BLAKE2b-256 965b0e281b86c5adb7d8f786b5299d7ead3e81c0977f2b704beca5c5b3b0efc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nyz_dynamic_design_builder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e6bc9efe5c79bb70d93c34dc562a818531fcdcc1fba585d93ed3089daf9fb60
MD5 ffa787393deb73ec5a2ff2fa7f4e9b2c
BLAKE2b-256 f28e6942f52d6568aff7ceede9d5eb6420a8f5c66f9f1ac0dd814e3c01509db9

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