Createapp scaffolds?

Is there a way to do startapp command(maybe 3rd party) so there will be urls.py and crud-urlpatterns, cet_absolute_url and maybe some other stuff?

How would you do that in the absence of the models and views?

(Also, take a look at cookiecutter and cookiecutter-django to see what has been done in that area.)

Maybe it is more like a startmodel command I am looking for.
I am also an opinionated use of the generec cbv could do it

The admin already does it by building its URLs from the ModelAdmin classes.

You could effectively do this by doing your own URL decoding and dispatch - but then you’re just recreating what Django already provides. (e.g. something along the lines of re_path('.*', my_custom_dispatcher))

A generic CBV can’t do it, because it doesn’t get instantiated until after a URL has been received and resolved, directing it to the view.

I don’t think I am explaining myself properly. :slight_smile:

I was thinking of doing a management command like “django-admin createscaffoldapp appname modelname fieldname” for example “django-admin createscaffoldapp books Book title”

Then (I think) django would be able to:

  • register the app in setting
  • make the _ _ str _ _ and get_absolute_url in the model
  • make the subdir in the templates dir
  • create the book_list.html with demo of a for book in books: {{book.title}}
  • create the book_detail.html
  • create the four crud views (generic)

… I think? :innocent:
I know the model and app will need all the rest of the fields and content. But the above is even for me as a beginner starting to be repetitive (yet time consuming).

I do realize that some of the process like naming the specific way the urlpattern paths are designed have to be chosen for me, but as a beginner I am fully okay with that. Maybe there is a corporate standard or way most people would agree it would be okay. My guess is something like (or whatever is more agreed upon by pros):

  • path(‘add/’, views.add, name=‘add’),
  • path(‘edit/int:id/’, views.edit, name=‘edit’),
  • path(‘delete/int:id/’, views.delete, name=‘delete’),
  • path(‘insert/’, views.insert, name=‘insert’),
  • path(‘update/int:id/’, views.update, name=‘update’),

I know about cookie-cutter, but I dont want to scaffold the whole project, only the individual app.

I know this mostly applies the beginners like me or maybe intermediate users (in a hurry), but I think Django could expand the project-start-supporting commands a bit more than they are right now.

Does this even make sense if you are making professional projects? (which I am not, not that anyone doubted this :smiley: )

The misinterpretation mistake was mine. :slightly_smiling_face:

You can create a cookiecutter for just an app.

I wasn’t suggesting to use django-cookiecutter, just to point out that there is a framework available for building what you describe.

A cookiecutter, at its most fundamental layer, creates a directory and a set of files while substituting text. It’s quite practical to build what you describe using it.

Edit: forget this: Could you or someone else point me in the right direction? I only find cookiecutter project stuff

Edit: I think I found it… https://cookiecutter.readthedocs.io/en/1.7.2/first_steps.html

Oh wait maybe someone has already built this “app starter”?

Also, if you want some ideas, see GitHub - wildfish/cookiecutter-django-crud: A cookiecutter template to create a Django app around a model with CRUD views using django-vanilla-views, a floppyforms ModelForm and WebTest tests using model mommy. and GitHub - smajda/cookiecutter-django-crud-app: A Django app template that sets up initial Create, List, Detail, and Update generic views, forms, urls, templates, and tests.

1 Like

This looks like it (quick look) is exactly what I was thinking of. :+1:

… But cookiecutter keeps throwing errors… :thinking:
(cant share error msg right now. On the phone)

error: invalid path '{{cookiecutter.app_name}}/templates/{{cookiecutter.app_name}}/{{cookiecutter.model_name|lower}}_confirm_delete.html'
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'

git status

fatal: not a git repository (or any of the parent directories): .git

which is weird as I am trying to clone the cookiecutter from my github fork of the original repo

I just watched a video of Django-Unicorn and it has a management command like “django-admin startunicorn Appname TemplateName” which does almost what I originally imagined without the need for CookieCutter.
How do I go and make one of those?