33

Is there any adequate scaffolding for Django?

It may be in the newly released 1.3 version, but I haven't found it yet.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
sultan
  • 5,978
  • 14
  • 59
  • 103
  • 2
    What do you mean by that? For admin you have admin app. For handling form-model you have ModelForm, for generic controllers you have generic views :) – Dmitry Shevchenko Mar 23 '11 at 14:09
  • 1
    when you say “scaffolding”, do you mean in this sense? http://stackoverflow.com/questions/5327933/define-scaffolding-with-respect-to-dynamic-data-and-asp-net-mvc – Paul D. Waite Mar 23 '11 at 14:12
  • It's all about `rails` scaffolding I was wondering if there anything like `manage.py scaffold SOME_MODEL` and if it acts like Rails one.:) It could make a little sense to me:) – sultan Mar 23 '11 at 14:15
  • @Paul D. Waite yes exact the same thing – sultan Mar 23 '11 at 14:16
  • 1
    I've found one https://github.com/mazelife/django-scaffold – sultan Mar 23 '11 at 14:28

7 Answers7

24

I've looked and not yet found something for Django quite like the Rails Generate command. Django has a bit of a different philosophy. It gives you tools to make doing things easily but doesn't actually do it for you (except the admin interface). In the grand scheme of things, I think this is OK. When I use rails' scaffolding I'm not able to often keep much of the auto-generated stuff. When I do, the django admin interface would probably also have worked and given me more functionality.

Instead, what I suggest is reading through the Django tutorial step 4, which introduces generic views, and then chapter 7 of the Django book which introduces forms. You have to be patient on chapter 7 because the authors think you want to know the minute details of the hard-way before they teach you the easy way. (try searching the page for the phrase django.forms)

In the end the amount of work you have to do between rails and django is equivalent, and maybe slightly less with Django. However you don't have one command to automatically give you boilerplate code to use as a foundation.

newz2000
  • 2,602
  • 1
  • 23
  • 31
8

So Django 1.3 still lacks 'scaffold' functionality. Not good. What is best in scaffold, is that it allows developer to immediately start with the project, without recalling all 'models', 'urls' and 'views' syntaxes.

Look at this example, let's start new project and app:

$django-admin startproject mysite
$python manage.py startapp blog

and now we need to manually 'START' everything, from almost empty files. BUT it would be very convenient to do it in this way (like in rails)

$python manage.py scaffold app:blog model:Post title:string content:text 

This should give us: models.py

class Post(models.Model):
    title    = models.CharField
    content  = models.TextField

views.py

def index(request):
    posts = Post.objects.all().order_by('-id')
    return render_to_response('blog/index.html', {'posts': posts})

and update urls.py somehow, ... or not, this is more complicated but less needed.

This should not be difficult to implement in future Django releases. I would do this if I had enough knowledge and experience in Django. Unfortunately I'm not doing many Django projects and that's why I need this functionality.

januszm
  • 1,166
  • 13
  • 24
  • What actually do we need is turns out into creation of model, model form, list template, view/edit templates and generation of urls – sultan Aug 04 '11 at 09:06
  • I agree. Even though I don't use much of the original scaffold, I still prefer to start quickly. Django turned me off really quickly. I love Python but hate having to cut-n-paste because of Django's shortcomings. – Natus Drew May 19 '16 at 23:20
7

This one is closer to rails-like scaffolding: https://github.com/modocache/django-generate-scaffold

rpq
  • 1,287
  • 2
  • 11
  • 9
2

there is actually a new django package that scaffolds everything you'd need in your application models, views, urls, tests and a lot more here https://github.com/Abdenasser/dr_scaffold

1

I just used the scaffold helper/management command provided by Django Common and it seems to have set up a decent chunk of boilerplate code. The options are limited, but decent enough.

I skimmed through the code and most of it looks fine. I needed to do a little bit of cleaning up, once the scaffolding was 'erected', though:

  • Separate import lines were added for each model created. Merged them.
  • The templates still carried the old (1.4) url template tag specs. Modified them to reflect the new (1.5) specs, i.e. enclosed the second parameter in single quotes, in each of the html files created, for each of the models.
  • Updated the main urls.py with an include for the app.urls module.
  • I use a non-standard settings.py setup - three separate files common.py, dev.py and prod.py for my setup. Had to add the app manually to the installed apps. YMMV.

(Will edit this list if I think of anything else)

That being said, looking at the amount of boilerplate code that I did NOT have to write, I'd say it does a very good job!

As of now, the repo seems pretty well-maintained - the last commit was 18 days ago at the time of writing this response. I'll probably submit a pull request/raise an issue about the problems I faced on their repo, some time soon.

1

I found this: https://github.com/madhusudancs/django-groundwork

Looks like it is exactly what you're looking for. Hope it helps.

Bernardo Siu
  • 1,359
  • 13
  • 13
0

You may check django-addview. It is meant to do boring, mundane steps needed to add new view automatically with nice ncurses GUI. What it does for you:

  • Extend CBV or write function
  • Fill parameters of CBV
  • Creates template in given location
  • Edits urls.py for you
  • Cares about all imports

Full disclosure: I wrote it.

yakxxx
  • 2,841
  • 2
  • 21
  • 22