Skip to main content

A Django package to print trimmed down models for easier sharing.

Project description

django_print_models

A Django package that provides a management command to print trimmed down models for easier sharing. Prints your models with just the field definitions, trimming out other methods, properties, etc.

This is handy when you want to ask ChatGPT or fellow humans a question where the context of your model field definitions is important (e.g. when trying to build a complex query), but the rest of your crappy model definition doesn't matter.

Installation

  1. pip install django-print-models
  2. Add django_print_models to your INSTALLED_APPS in Django settings.

Usage

python manage.py print_models <app_name> <model_name1> <model_name2> ...

Example

Given the following model definitions:

import datetime
from django.db import models
from django.utils import timezone
from django.contrib import admin


class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    def __str__(self):
        return self.question_text

    @admin.display(
        boolean=True,
        ordering='pub_date',
        description='Published recently?',
    )

    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) <= self.pub_date <= now


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

    def __str__(self):
        return self.choice_text

print_models will print the following:

> python manage.py print_models polls Question Choice
class Question(models.Model):
    id = models.BigAutoField(null=False, blank=True, db_index=False)
    question_text = models.CharField(max_length=200, null=False, blank=False, db_index=False)
    pub_date = models.DateTimeField(null=False, blank=False, db_index=False)

class Choice(models.Model):
    id = models.BigAutoField(null=False, blank=True, db_index=False)
    question = models.ForeignKey("Question", null=False, blank=False, db_index=True)
    choice_text = models.CharField(max_length=200, null=False, blank=False, db_index=False)
    votes = models.IntegerField(null=False, blank=False, db_index=False)

Obviously in this simple example it would have been quite easy to just copy/paste the relevant model definitions, but for larger, more complex models this becomes tedious.

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

django_print_models-0.4.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.

django_print_models-0.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file django_print_models-0.4.tar.gz.

File metadata

  • Download URL: django_print_models-0.4.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for django_print_models-0.4.tar.gz
Algorithm Hash digest
SHA256 2cb2d2f0abe2e2a883e3dfb58d7689b006c11f4783cabef3164defcc69ec6b15
MD5 87b2aaf881baf6641853d1ee47ccba31
BLAKE2b-256 5a02f8c008e591bef79b8091e457cdc1f01963034728dfb0fdcf327713e5cd85

See more details on using hashes here.

File details

Details for the file django_print_models-0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_print_models-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9dffd553c733c794af801369d237e4d0020b56d3803467990090a0f78f0cfa52
MD5 737072c841bc8e82f070e8e469a22f62
BLAKE2b-256 657090c8b8e153fa3ce9a4b533d94feb7e8395984015c78d2f5fca7fc8106d2c

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