django-autogen 0.1.6
Automatic file generator for Django models
Requires Python: >=3.6

# Django AutoGen

[![PyPI version](https://badge.fury.io/py/django-autogen.svg)](https://badge.fury.io/py/django-autogen)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Automatically generate admin panels, serializers, and URLs for your Django models with relationship support.

Developed by [FKT YazÄ±lÄ±m](https://fktyazilim.com)

## Installation

```bash
pip install django-autogen
```

After installation, make sure the Scripts directory is in your PATH to access the command directly.

## Usage

Django AutoGen can generate Django admin configurations, DRF serializers, and URL patterns from your models.

### Basic Usage

To generate admin configuration for a specific model:

```bash
django-autogen app_name model_name
```

### Specifying Django Settings

If Django settings are not automatically detected, you can specify them using the `--settings` parameter:

```bash
django-autogen app_name model_name --settings=myproject.settings
```

This is especially helpful when working with different Django project structures or custom settings modules.

### API Generation

To generate both admin and API (DRF serializers and viewsets):

```bash
django-autogen app_name model_name -api
```

### Log Level

You can specify the log level for more detailed output:

```bash
django-autogen app_name model_name --log-level DEBUG
```

## Features

### Intelligent Django Settings Detection

- Automatically finds your Django project by locating `manage.py`
- Detects common settings modules (app_name.settings, config.settings, etc.)
- Provides manual override with `--settings` parameter

### Admin Panel Configuration

- Automatically configures `list_display` with all model fields
- Sets up `search_fields` for text and character fields
- Creates `list_filter` for relationship fields
- Generates `TabularInline` for related models (OneToMany relationships)

### API Generation (with `-api` flag)

- Creates DRF serializers with proper relationships
- Adds nested serializers for ForeignKey relationships
- Configures ViewSets with standard CRUD operations
- Sets up routers for RESTful URL patterns

### Relationship Support

Django AutoGen automatically handles:

- ForeignKey relationships
- ManyToMany relationships
- OneToOne relationships 
- Reverse relationships (for admin inlines)

## Example

Starting with a Django model like:

```python
from django.db import models
from django.contrib.auth.models import User

class Category(models.Model):
    name = models.CharField(max_length=100)
    
    def __str__(self):
        return self.name

class Article(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    
    def __str__(self):
        return self.title
```

Run Django AutoGen:

```bash
django-autogen myapp Article -api
```

If Django settings are not detected automatically:

```bash
django-autogen myapp Article -api --settings=myproject.settings
```

This will generate:

1. Admin configuration with proper display, search, and filter fields
2. Serializers with nested representation of relationships
3. ViewSets and router configuration for the API

## Troubleshooting

### Common Issues

1. **Command not found**: Ensure the Python Scripts directory is in your PATH, or use the full path to the command:
   ```bash
   C:\path\to\python\Scripts\django-autogen.exe app_name model_name
   ```

2. **Django settings not found**: Use the `--settings` parameter to specify your Django settings module:
   ```bash
   django-autogen app_name model_name --settings=myproject.settings
   ```

3. **Application or model not found**: Check that you're running the command from the Django project root (where `manage.py` is located) or use absolute paths.

## Development

### Setup for Development

```bash
# Clone the repository
git clone https://github.com/yourusername/django-autogen.git
cd django-autogen

# Install in development mode
pip install -e .
```

### Building the Package

```bash
pip install build twine
python -m build
```

### Publishing to PyPI

```bash
python -m twine upload dist/*
```

## About

Django AutoGen is developed and maintained by [FK YazÄ±lÄ±m](https://fktyazilim.com), a software development company specializing in web technologies and Django applications.

## Contact

For support, feature requests, or custom development:
- Website: [fktyazilim.com](https://fktyazilim.com)
- Email: info@fktyazilim.com

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.