Skip to main content

A Django management command to generate views and serializers based on models.

Project description

Django View and Serializer Generator This Django management command automatically generates views.py and serializers.py files with basic viewsets and serializers for each model defined in the project’s models.py file. It saves development time by creating boilerplate code for API views and serializers based on your models.

Features Automatically generates views.py and serializers.py files based on models defined in a specified Django app. Creates a ModelViewSet for each model in views.py to enable CRUD operations. Generates a ModelSerializer for each model in serializers.py, including all model fields. Installation To install this library, use pip:

bash Copy code pip install django-view-serializer-generator Then, add the app to your Django project's INSTALLED_APPS:

python Copy code

settings.py

INSTALLED_APPS = [ # Other installed apps 'view_serializer_generator', # Add the generator app ] Usage Navigate to your Django project directory where manage.py is located.

Run the command to generate views and serializers:

bash Copy code python manage.py generate_views_and_serializers The command will look for models defined in the app specified in the code and generate views.py and serializers.py with the appropriate viewsets and serializers.

Example Output The command creates views.py and serializers.py in the specified app (e.g., Paypal), with code similar to:

serializers.py

python Copy code from rest_framework import serializers from .models import YourModel

class YourModelSerializer(serializers.ModelSerializer): class Meta: model = YourModel fields = 'all' views.py

python Copy code from rest_framework import viewsets from .models import YourModel from .serializers import YourModelSerializer

class YourModelViewSet(viewsets.ModelViewSet): queryset = YourModel.objects.all() serializer_class = YourModelSerializer Folder Structure To follow best practices, maintain the following folder structure:

markdown Copy code myproject/ ├── myapp/ │ ├── management/ │ │ └── commands/ │ │ └── generate_views_and_serializers.py │ ├── migrations/ │ ├── init.py │ ├── models.py │ ├── serializers.py │ ├── views.py │ ├── urls.py ├── manage.py ├── settings.py Customizing the Command By default, this command looks for an app named Paypal. If your app has a different name, update the app_name variable in generate_views_and_serializers.py:

python Copy code app_name = 'YourAppName' License This project is licensed under the MIT License - see the LICENSE file for details.

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

auto_view_generator-0.1.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

auto_view_generator-0.1.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file auto_view_generator-0.1.3.tar.gz.

File metadata

  • Download URL: auto_view_generator-0.1.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for auto_view_generator-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c31b54ccfae2a8293f74a02df44c073d98a7ec7b402144109228cf82d9b8f3d9
MD5 a518f8eef7409e16a86b5abfca1698e3
BLAKE2b-256 1159338ac3e2dec52fc9fe4570151b1dd1f192210f2af0e39b4424e2a704fae4

See more details on using hashes here.

File details

Details for the file auto_view_generator-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for auto_view_generator-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4058496fe0f651bdc4c3834bab43ec0694cdd2f026c94ddf996e05b211f5996a
MD5 b23a36308e3389f5d24ff85d4b1dcd2b
BLAKE2b-256 316dd91b41754ca6ec2d007037f245cb7f4e75be5638e3623d4c2248f86a6dcf

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