If you tired to create template files, views etc from scratch every time you created new django model - this app is for you.
Django-expand provides:
- templates
- views
- urls
- forms
- Install:
pip install git+git://github.com/FZambia/django-expand.git
-
Add
'expand'
in INSTALLED_APPS -
Create new django model, ex class Contact in
contact
app:
# contact/models.py
from django.db import models
from django.core.urlresolvers import reverse
class Contact(models.Model):
first_name = models.CharField(u"contact first name", max_length=30)
last_name = models.CharField(u"contact last name", max_length=30)
email = models.EmailField(u"contact email address")
phone = models.CharField(u"contact phone number", max_length=30)
created_at = models.DateTimeField(u"created at", auto_now_add=True)
updated_at = models.DateTimeField(u"updated_at", auto_now=True)
def __unicode__(self):
return "%s %s" % (self.first_name, self.last_name)
def get_absolute_url(self):
return reverse("contact_contact_detail", kwargs={'pk':self.pk})
Note that get_absolute_url method is required and url name must be constructed from app_label and model_name as follows: "applabel_modelname_detail"
- Include urls in your application
urls.py
:
url(r'', include('contact.urls')),
-
remove
views.py
file if it's empty yet. -
run manage.py command:
python manage.py expand --app=contact --model=Contact
-
Open your browser - go to '/contact/' location and enjoy result!
-
--append
command line flag can help you to create another model from the same app.
This tool is nice for new projects when you do not have any files in app yet. This is just a start point which helps you to begin and makes some routine things instead of you. But nothing more.