generator-broagency v0.0.1
generator-bro
This generator help you create django projects, apps, models and views very faster. See usage section for more information. This project based on yeoman generator.
Install
npm install -g git://github.com/lutowolk/generator-bro Usage
Package contain next generators:
bro
This generator will create a django project.
Run
$ yo bro [<args>] [<options>]Args
First arg - project name;
Second arg - django database backend. One of this: postgresql_psycopg2, mysql, sqlite3, oracle;
Third arg - database user.
Four arg - database user password.
All this args is not required.
Example
This command create project with name blog.
$ yo bro blogProject will be have next file structure:
blog
├─ client
└─ server
├─ apps
| └─ __init__.py
├─ libs
├─ contrib
├─ config
| ├─ settings
| | ├─ installed_apps.py
| | ├─ local.py
| | ├─ settings.py
| | ├─ __local.py
| | └─ __init__.py
| ├─ urls.py
| ├─ wsgi.py
| └─ __init__.py
├─ templates
| └─ base.html
├─ manage.py
├─ requirments.txt
└─ __init__.pybro:sub
This generator will create a django app in server.apps directory. Also new app will be include to settings and root urlconf.
Note: before running this command move to project directory.
Run
$ yo bro:sub <app_name> [<options>]Example
This command create app with name news in .
$ yo bro:sub newsApp will be have next file structure:
news
├─ models
| ├─ mixins
| | └─ __init__.py
| └─ __init__.py
├─ views
| ├─ mixins
| | └─ __init__.py
| └─ __init__.py
├─ factories
| └─ __init__.py
├─ admin
| ├─ mixins
| | └─ __init__.py
| └─ __init__.py
├─ tests
| ├─ models
| | └─ __init__.py
| ├─ views
| | └─ __init__.py
| └─ __init__.py
└─ __init__.pybro:model
This generator will create a django model in server.apps.your_app.models directory. For new model will be created admin class. If model containg field with name slug for this field will be created prepopulated field.
Admin and model classes will be imported in __init__.py files.
Note: before running this command move to project directory.
Run
$ yo bro:model <app_name:model_name> [<field_name:field_type[:arg1,arg2=val]> ...] [<options>]Options
-s,--def-saveCreate model method save for next overriding.-p,--prepopulatedSet prepopulated field name for slug field. Use this option if field slug exist and prepopulated field name differs from name or title.
Example
This command create model Blog in app blogs in .
$ yo bro:model blogs:Blog title:char slug:slug content:text publish:bool:default=TrueFile content for new file blogs.models.blog.py:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext as _
class Blog(models.Model):
title = models.CharField(verbose_name=_("title"), max_length=255)
slug = models.SlugField(verbose_name=_("slug"))
content = models.TextField(verbose_name=_("content"))
publish = models.BooleanField(verbose_name=_("publish"), default=True)
class Meta:
verbose_name = _("Blog")
verbose_name_plural = _("Blogs")
def __unicode__(self):
return self.title
# your custom methodsStructure blogs app after creating model:
blogs
├─ models
| ├─ mixins
| | └─ __init__.py
| ├─ blog.py
| └─ __init__.py
├─ admin
| ├─ mixins
| | └─ __init__.py
| ├─ blog.py
| └─ __init__.py
└─ __init__.pybro:view
With help this generator you may create generic view for your model. Just enter your model name and generator create views for this model. Generator support next generic view: ListView, DetailView, CreateView, UpdateView and DeleteView. You can tell the generator what kind of views you want to create with options.
Note: before running this command move to project directory.
Run
$ yo bro:model <app_name:model_name> [<options>]Options
--listfor createListView--detailfor createDetailView--createfor createCreateView--updatefor createUpdateView--delfor createDeleteView--paginateset property paginate_by for class ListView usage this options with optionlist, default value5
Example
This command create all views for model Blog (see this model in above).
$ yo bro:view blogs:Blog --list --detail --create --update --delAfter this command will be executed, will be created five classes in file server/apps/blogs/views/blog.py:
BlogListViewBlogDetailViewBlogCreateViewBlogUpdateViewBlogDeleteView
Also will be created new form class BlogForm in file server/apps/blogs/forms/blog.py and include in BlogCreateView and BlogUpdateView. This views will be included in urls conf (server/apps/blogs/urls.py). With view BlogDetailView will be created method get_absolute_url in model Blog. For this views also will be created base templates witch contain data about models.
New files:
# server/apps/blogs/views/blog.py# server/apps/blogs/forms/blog.py# server/templates/blogs/blog_detail.html# server/templates/blogs/blog_form.html# server/templates/blogs/blog_list.html
Changed files:
# server/apps/blogs/urls.py# server/apps/blogs/models/blog.py# server/apps/blogs/forms/__init__.py
Sponsors
This project is developed with the financial support of bro.agency.
Contributing
If you find errors or you know how improve this project please create issue in this page.
11 years ago