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.
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?
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 )
The misinterpretation mistake was mine.
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.
This looks like it (quick look) is exactly what I was thinking of.
ā¦ But cookiecutter keeps throwing errorsā¦
(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?