Skip to main content

Provides Ruby on Rails-like command line functionalities, models and helper functions so you can focus on development and removes the pain of repeating frequent actions.

Project description

Introduction

Django simplify provides Ruby on Rails-like command line functionalities, models and helper functions so you can focus on development and removes the pain of repeating frequent actions.

Requirements

  • Python 3.6 and above

  • Django (tested with 3.1, probably works with any version that supports

    Python 3)

Installation

django-simplify can be installed via pip.

$ pip install django-simplify

Then just add simplify to your INSTALLED_APPS.

Below are several example commands you can run.

$ python manage.py create_app <app_name>

Features

  • timestamp for every model

  • alphabetic filter for admin

  • model, view, template and url route generator

  • automatic import

Helper models

  • simplify.helpers.model_helper.TimeBasedModel
    • Provides the created_at and updated_at fields for timestamp

  • simplify.helpers.model_helper.NamedTimeBasedModel
    • Provides the name, created_at and updated_at fields.

  • simplify.helpers.admin_helper.AlphaNumericFilterAdmin
    • when subclassed, it allows the items to be filtered alphabetically by either A-Z or 0-9

    • Note: for this to work, you must specify values for alphanumeric_filter in the model admin.

Usage

# models.py
from simplify.helpers.model_helper import TimeBasedModel, NamedTimeBasedModel

class MyModel(TimeBasedModel):
    extra_fields = ....
# admin.py
from simplify.helpers.admin_helper import AlphaNumericFilterAdmin

class MemberAdmin(AlphaNumericFilterAdmin):
    alphanumeric_filter = ["first_name", "last_name", 'age'] # this part is what creates the filter
    list_filter = ['age']
    list_display = ['first_name', 'last_name',]

Management commands

1. create_app

  • automatically adds a urls.py file after app is created.

  • adds newly created app in the settings.py file under INSTALLED_APPS

  • creates index, edit, create and detail view and respective templates

  • adds the app route to your project’s urls.py file

Usage

$ python manage.py create_app <app_name>

2. create_model

Creates a model and their respective fields. the following types maps to respective Django model fields. It will also add the app to the django admin too.

  • 121, o2o or set -> OneToOneField

  • bool -> BooleanField

  • date -> DateField

  • datetime or dt -> DateTimeField

  • dict or m2m -> ManyToManyField

  • email -> EmailField

  • file -> FileField

  • list or fk -> ForeignKey

  • float -> FloatField

  • dec -> DecimalField

  • img or image -> ImageField

  • int -> IntegerField

  • str or char -> CharField

  • txt or text -> TextField

Usage

$ python manage.py create_app <app_name> <model_name> field_name:type field_name:type ...

an example

$ python manage.py create_app member Member first_name:text last_name:text age:int

will generate the following code in the member/models.py file

class Member(TimeBasedModel):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    age = models.IntegerField(default=0)

    def __str__(self):
        return self.first_name

Specifying relationships

Specifying ForeignKey, OneToOneField or ManyToManyField is quite easy. just add an =<related_model>. See example

$ python manage.py create_app <app_name> <model_name> field_name:type=related_model

# an example
# if the related model is in the same models.py file, specify it as app_name.Model
$ python manage.py create_app author Author name:char books:fk=Book # or
$ python manage.py create_app author Author name:char books:fk=author.Book

# if in a different app. (say book model)
# obviously you should be able to substitute fk with m2m, o2o, 121
$ python manage.py create_app author Author name:char books:fk=book.Book

will create the following

class Author(TimeBasedModel):
    name = models.CharField(max_length=50)
    books = models.ForeignKey('book.Book', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

3. create_view

Creates a view, generate its respective template and adds the path in the urls.py file

Usage

$ python manage.py create_view <app_name> <view_name>

an example

$ python manage.py create_view member MemberDetail

Todo

  • add more helper functions

  • add documentation

Acknowledgements

I’d like to say a big thank you to God without which this wouldn’t be possible. I would also like to say thanks to everyone who has and will contribute to this in the future.

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-simplify-0.1.6.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

django_simplify-0.1.6-py3.8.egg (27.2 kB view details)

Uploaded Egg

File details

Details for the file django-simplify-0.1.6.tar.gz.

File metadata

  • Download URL: django-simplify-0.1.6.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for django-simplify-0.1.6.tar.gz
Algorithm Hash digest
SHA256 89d6d66ccd64126a166a1b9999d4aeacf0f413ce757e9cf2bdf08e9ef3c4b2e1
MD5 53f27f6d6b968d7b6e158a5fbd3242a7
BLAKE2b-256 290e39c2294159793f24e28e395f26d928a8a187554ab7949607ca931f91b153

See more details on using hashes here.

File details

Details for the file django_simplify-0.1.6-py3.8.egg.

File metadata

  • Download URL: django_simplify-0.1.6-py3.8.egg
  • Upload date:
  • Size: 27.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for django_simplify-0.1.6-py3.8.egg
Algorithm Hash digest
SHA256 0b4e1aaff88ac32a49dceeb0146bb8c976f8237e0dc3b6f2cc05527986829956
MD5 5bb7a8e81fe604a17fb7e77d1e32c5dd
BLAKE2b-256 71881637ad073b1121a59dd532e1324c8d35eed711c784c9dd0fd0569017c5ab

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