Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add django-admin startapp template #3358

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/cookiecutter/cookiecutter-django/issues/528#issuecomment-212650373
.. _#1725: https://github.com/cookiecutter/cookiecutter-django/issues/1725#issuecomment-407493176
.. _startapp: https://docs.djangoproject.com/en/dev/ref/django-admin/#startapp
4 changes: 4 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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)
Expand Down Expand Up @@ -327,6 +328,9 @@ def remove_drf_starter_files():
"{{cookiecutter.project_slug}}", "users", "tests", "test_swagger.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():
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/startapp_template/admin.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Define and register {{ '{{' }} app_name {{ '}}' }} app admin models."""
from django.contrib import admin

# Register your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Define serializers for the {{ '{{' }} app_name {{ '}}' }} api."""
from rest_framework import serializers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Define API views for {{ '{{' }} app_name {{ '}}' }} app."""
5 changes: 5 additions & 0 deletions {{cookiecutter.project_slug}}/startapp_template/apps.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class {{ '{{' }} camel_case_app_name {{ '}}' }}Config(AppConfig):
name = '{{ "{{" }} app_name {{ "}}" }}'
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/startapp_template/forms.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Define {{ '{{' }} app_name {{ '}}' }} app forms."""
from django.utils.translation import gettext_lazy as _

# Create your forms here.
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/startapp_template/models.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Define {{ '{{' }} app_name {{ '}}' }} app models."""
from django.db import models

# Create your models here.
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/startapp_template/tasks.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Define {{ '{{' }} app_name {{ '}}' }} app Celery tasks."""
from config import celery_app
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Define factories to generate testing data."""
from typing import Any, Sequence

from factory import Faker, post_generation
from factory.django import DjangoModelFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pytest
from django.urls import reverse

pytestmark = pytest.mark.django_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pytest
from django.urls import resolve, reverse

pytestmark = pytest.mark.django_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pytest
from django.test import RequestFactory

pytestmark = pytest.mark.django_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Module for all {{ '{{' }} app_name {{ '}}' }} Form Tests.
"""
import pytest
from django.utils.translation import gettext_lazy as _

pytestmark = pytest.mark.django_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytestmark = pytest.mark.django_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pytest
from django.urls import resolve, reverse

pytestmark = pytest.mark.django_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/startapp_template/views.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Define {{ '{{' }} app_name {{ '}}' }} app views."""
from django.shortcuts import render

# Create your views here.