Giter Site home page Giter Site logo

django-generate-scaffold's Introduction

django-generate-scaffold build-status endorse

Generate a Django model, views, URLconf, and templates using a single command.

Quickstart

A screencast introducing django-generate-scaffold is available here.

Usage

Generating Models, Views, URL Patterns, and Templates

  • Install django-generate-scaffold:

      $ pip install django-generate-scaffold
    
  • Add generate_scaffold to your INSTALLED_APPS

  • Run the generatescaffold management command:

      $ python manage.py generatescaffold --help
      ... displays usage
    
  • Create a model using the syntax in the help message:

      $ python manage.py generatescaffold blogs Post title:string body:text is_public:bool blog:foreignkey=Blog
      ... Generates a Post model, with title (CharField), body (TextField),
      ...     is_public (BooleanField), and blog (ForeignKey) fields.
    

Generating Views, etc. Based on Existing Models

  • Alternatively, you can generate views, urlpatterns, and templates for an existing model:

      $ python manage.py generatescaffold blogs --model Post
      ... Generates views, etc. for Post
    
  • Note that if the model specified with the --model option has a DateField or a DateTimeField, date-based generic views will be generated based on that field. To specify a specific field to use, pass in the --timestamp-field option:

      $ python manage.py generatescaffold blogs --model Post --timestamp-field ctime
    

Limitations When Using Existing Models

For best results, existing models should implement a get_absolute_url method which conforms to the urlpatterns used by django-generate-scaffold:

    @models.permalink
    def get_absolute_url(self):
        return ('<app_name>_<model_name>_detail', (), {'pk': self.pk})

Not conforming to this model will lead to broken links and potentially other issues when rendering templates.

Development

django-generate-scaffold is currently in ALPHA.

Running Tests

In order to run the test suite, install your local version of django-generate-scaffold and start a Selenium server and issue the following commands:

    $ cd django-generate-scaffold
    $ python setup.py install --force
    $ cd test_project
    $ python test_app/tests/runtests.py

Consult .travis.yml for the exact steps necessary to run the test suite.

Autotesting via watchr

By installing the gems in the Gemfile, you can automatically run all non-Selenium based tests every time a file is modified:

    $ watchr autotest.rb

How to Contribute

  • Propose new features or report bugs by creating an issue on Github.
  • Add new features, tests, or fix stuff and issue a pull request.
  • Create a better, more eloquent screencast with less stammering.

Issues

If you experience any issues, please create an issue on Github.

django-generate-scaffold's People

Contributors

drillbits avatar modocache avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-generate-scaffold's Issues

templates and css+static

can you share your sitebase.html, and add to README.md that without sitebase.html, which can be found by django, django-generate-scaffold doesnt work

Scaffold should generate basic unit/integration tests

Rails' generate command generates:

  • Unit tests for models
  • Functional tests for controllers and views (templates)
  • Fixtures to seed DB with valid models

Having these examples around makes it a lot easier to pick up on how to write tests, so I'd like the same feature for django-generate-scaffold as well.

path issues in windows

Inside file:
\generate_scaffold\utils\directories.py

add:

dir_suffix = dir_suffix.replace('/', os.path.sep)

to make the windows paths work properly.

Write tests

Tests should be added before any new features.

timezone warnings, when use_tz = True

When I display single item in archive index, I get a RuntimeWarning:

DateTimeField received a naive datetime (2009-11-30 00:00:00) while time zone support is active.
Because of that, the datetime values in "Month Archive" are displayed incorrectly.

USE_TZ = False

fixed the problem, but I guess it's not good If I want to use timezones..

Syntax error on install with Python 3.4 ?

When installing the latest dev build (or the master branch), I get the following error:

Running setup.py install for django-generate-scaffold
File "/Users/Danny/Projects/InterviewProject/dj15_env/lib/python3.4/site-packages/generate_scaffold/management/commands/generatescaffold.py", line 186
exec code in globals()
^
SyntaxError: invalid syntax

Create view fails on a model with a File attribute

Steps to recreate:

  1. Generate a scaffold where one of the model fields is a file type. Eg:
../venv/bin/python manage.py generatescaffold foo Foo name:char description:text screenshot:file
  1. python manage.py runserver
  2. Navigate to the Create View in the browser.
  3. Fill in the form, taking care to choose a file in the file picker.
  4. Click the Create button. The form displays a message above the file picker: "This field is required."

This was found in a clean virtualenv running Python 2.7, Django 1.4.1 and django-generate-scaffold 0.0.5.

Error generating model

I'm using django-generate-scaffold for the first time and I'm getting errors when running the generatescaffold command. I'm still fairly new to Python/Django and I'm the one setting up my app (also for the first time). Here's some pertinent information.

The tree

├── bookreview
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── books
│   ├── __init__.py
│   ├── admin.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── fabfile.py
├── manage.py
└── requirements.txt

The requirements.txt (after pip freeze)

Django==1.6.2
Fabric==1.8.1
django-generate-scaffold==0.0.5a0
djangorestframework==2.3.12
ecdsa==0.10
paramiko==1.12.1
pycrypto==2.6.1
wsgiref==0.1.2

The command:

python manage.py generatescaffold books Author first_name:string last_name:string

The error:

            backup  books/models.py
            revert  books/models.py
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/generate_scaffold/management/commands/generatescaffold.py", line 65, in handle
    self.generate_scaffold(*args, **options)
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/generate_scaffold/management/commands/generatescaffold.py", line 169, in generate_scaffold
    reload_django_appcache()
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/generate_scaffold/utils/cacheclear.py", line 16, in reload_django_appcache
    for app in cache.get_apps():
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/db/models/loading.py", line 139, in get_apps
    self._populate()
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/Users/andymatthews/.virtualenvs/drf/lib/python2.7/site-packages/django/db/models/loading.py", line 95, in load_app
    self.handled.add(app_name)
AttributeError: 'dict' object has no attribute 'add'

django.utils.timezone import error on Django 1.3.

django.utils.timezone is only available on Django 1.4+, but the package metadata specifies Django 1.3+ as a dependency. As a result, attempting to use generate_scaffold/templates/generate_scaffold/models/models.txt will raise an error when using Django 1.3.

Either the package metadata should be changed to support only 1.4+, or a change to the template needs to be made.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.