mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-15 09:24:52 +03:00
Add django-admin startapp template
django-admin has a --template flag that lets you specify a directory to base new apps off of. I've added a `startapp_template` directory to the top level directory, updated the post gen hook to remove any files that may not be needed, and updated the documentation for this new process.
This commit is contained in:
parent
177c1ab0a1
commit
fd25955dfd
|
@ -45,7 +45,7 @@ Others
|
|||
|
||||
#. ``jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'now'.``: please upgrade your cookiecutter version to >= 1.4 (see `#528`_)
|
||||
|
||||
#. New apps not getting created in project root: This is the expected behavior, because cookiecutter-django does not change the way that django startapp works, you'll have to fix this manually (see `#1725`_)
|
||||
#. To create a new app using the recommended directory structure, run `django-admin startapp --template=../startapp_template myappname` from inside the project root. This template can be customized to suit your needs. (see `startapp`_)
|
||||
|
||||
.. _#528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373
|
||||
.. _#1725: https://github.com/pydanny/cookiecutter-django/issues/1725#issuecomment-407493176
|
||||
.. _startapp: https://docs.djangoproject.com/en/dev/ref/django-admin/#startapp
|
||||
|
|
|
@ -101,6 +101,7 @@ def remove_celery_files():
|
|||
os.path.join(
|
||||
"{{ cookiecutter.project_slug }}", "users", "tests", "test_tasks.py"
|
||||
),
|
||||
os.path.join("startapp_template", "tasks.py-tpl"),
|
||||
]
|
||||
for file_name in file_names:
|
||||
os.remove(file_name)
|
||||
|
@ -318,6 +319,9 @@ def remove_drf_starter_files():
|
|||
"{{cookiecutter.project_slug}}", "users", "tests", "test_drf_views.py"
|
||||
)
|
||||
)
|
||||
shutil.rmtree(os.path.join("startapp_template", "api"))
|
||||
os.remove(os.path.join("startapp_template", "tests", "test_drf_urls.py-tpl"))
|
||||
os.remove(os.path.join("startapp_template", "tests", "test_drf_views.py-tpl"))
|
||||
|
||||
|
||||
def remove_storages_module():
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
"""Define and register {{ '{{' }} app_name {{ '}}' }} app admin models."""
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
"""Define serializers for the {{ '{{' }} app_name {{ '}}' }} api."""
|
||||
from rest_framework import serializers
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
"""Define API views for {{ '{{' }} app_name {{ '}}' }} app."""
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class {{ '{{' }} camel_case_app_name {{ '}}' }}Config(AppConfig):
|
||||
name = '{{ "{{" }} app_name {{ "}}" }}'
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
"""Define {{ '{{' }} app_name {{ '}}' }} app forms."""
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Create your forms here.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
"""Define {{ '{{' }} app_name {{ '}}' }} app models."""
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
"""Define {{ '{{' }} app_name {{ '}}' }} app Celery tasks."""
|
||||
from config import celery_app
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
"""Define factories to generate testing data."""
|
||||
from typing import Any, Sequence
|
||||
|
||||
from factory import Faker, post_generation
|
||||
from factory.django import DjangoModelFactory
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import pytest
|
||||
from django.urls import reverse
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import pytest
|
||||
from django.urls import resolve, reverse
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import pytest
|
||||
from django.test import RequestFactory
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
"""
|
||||
Module for all {{ '{{' }} app_name {{ '}}' }} Form Tests.
|
||||
"""
|
||||
import pytest
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import pytest
|
||||
from django.urls import resolve, reverse
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import pytest
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.messages.middleware import MessageMiddleware
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.http import HttpRequest
|
||||
from django.test import RequestFactory
|
||||
from django.urls import reverse
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
"""Define {{ '{{' }} app_name {{ '}}' }} app views."""
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
|
Loading…
Reference in New Issue
Block a user