Metadata-Version: 2.1
Name: django-print-models
Version: 0.4
Summary: A Django package to print trimmed down models for easier sharing.
Author-email: Mitchel Humpherys <mitch.special@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Mitchel Humpherys
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/mgalgs/django_print_models
Project-URL: Bug Tracker, https://github.com/mgalgs/django_print_models/issues
Keywords: django
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3
Description-Content-Type: text/markdown
License-File: LICENSE

# `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:

```python
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.
