== Introduce ==
A command(create_app) for django, auto generate CRUD file and
method(view/urls/template).
you can download from:
http://vik.haoluobo.com/blog/wp-content/uploads/2009/03/hidjangoen.zip
== how to use ==
Put django_extensions folder to you project app directory, and add
django_extensions to INSTALLED_APPS.
run command, manage.py create_app <app_name>
== demo ==
hidjango is a demo for this command(create_app)。
 1. run "manage.py create_app blog" to create a app named blog.
 1. open \hidjango\settings.py, and add hidjango.blog to INSTALLED_APPS.
 1. run "manage.py syncdb" to initialize db.
 1. open \hidjango\urls.py, and add (r'^',
include('hidjango.blog.urls')), (note: this url map has added, no need
to do again).
 1. run "manage.py runserver" to start django's develop server.
 1. open exploere and input http://127.0.0.1:8000/.
== note ==
 * some code from
django-command-extensions(http://code.google.com/p/django-command-extensions
)。
 * this command is simple now, need to add some option.
== template for create_app ==
=== files ===
{{{
/django_extensions/conf/app_template/
|~templates/
| `~{{ app_name }}/
|   |-base.html
|   |-edit.html
|   |-list.html
|   `-new.html
|~templatetags/
| `-__init__.py
|-__init__.py
|-admin.py
|-forms.py
|-models.py
|-tests.py
|-urls.py
`-views.py
}}}
=== views.py ===
{{{
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django.shortcuts import render_to_response, get_object_or_404
from django import template
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

from forms import {{ Model }}Form
from models import {{ Model }}

def list(request, template_name = '{{ model }}/list.html'):
    return render_to_response(template_name, {
            "{{ model }}s": {{ Model }}.objects.all(),
            }, context_instance=template.RequestContext(request))

def new(request, form_class={{ Model }}Form, template_name = '{{ model
}}/new.html'):
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            {{ model }} = form.save(commit=False)
            {{ model }}.save()
            return HttpResponseRedirect(reverse("{{ model }}_list"))
    else:
        form = form_class()
    return render_to_response(template_name, \
            { "form": form }, \
            context_instance=template.RequestContext(request))

def edit(request, id, form_class={{ Model }}Form, template_name="{{
model }}/edit.html"):
    {{ model }} = get_object_or_404({{ Model }}, id=id)
    if request.method == "POST":
        form = form_class(request.POST, instance={{ model }})
        if form.is_valid():
            {{ model }} = form.save(commit=False)
            {{ model }}.save()
            return HttpResponseRedirect(reverse("{{ model }}_list"))
    else:
        form = form_class(instance={{ model }})
    return render_to_response(template_name, {
            "form": form,
            "{{ model }}": {{ model }},
            }, context_instance=template.RequestContext(request))

def delete(request, id):
    {{ model }} = get_object_or_404({{ Model }}, id=id)
    {{ model }}.delete()
    return HttpResponseRedirect(reverse("{{ model }}_list"))
}}}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to