Improve structure of sampleproject.

This commit is contained in:
Emil Stenström 2022-07-18 09:13:36 +02:00
parent 18ee5ad3b0
commit c0ed45b920
7 changed files with 14 additions and 8 deletions

View file

@ -4,6 +4,3 @@ from django.apps import AppConfig
class CalendarappConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "calendarapp"
def ready(self):
from components.calendar import calendar # NOQA

View file

@ -0,0 +1,2 @@
.calendar-component { width: 200px; background: pink; }
.calendar-component span { font-weight: bold; }

View file

@ -1 +1 @@
Today's date is <span>{{ date }}</span>
<div class="calendar-component">Today's date is <span>{{ date }}</span></div>

View file

@ -0,0 +1,3 @@
(function(){
document.querySelector(".calendar-component").onclick = function(){alert("Clicked calendar!")}
})()

View file

@ -3,8 +3,9 @@ from django_components import component
@component.register("calendar")
class Calendar(component.Component):
# Note that Django will look for templates inside `[your app]/components` dir
# To customize which template to use based on context override get_template_name instead
# Note that Django will look for templates inside `[your apps]/components` dir and
# `[project root]/components` dir. To customize which template to use based on context
# you can override def get_template_name() instead of specifying the below variable.
template_name = "calendar/calendar.html"
# This component takes one parameter, a date string to show in the template
@ -14,5 +15,5 @@ class Calendar(component.Component):
}
class Media:
css = "calendarapp/components/calendar/calendar.css"
js = "calendarapp/components/calendar/calendar.js"
css = "calendar/calendar.css"
js = "calendar/calendar.js"

View file

@ -122,6 +122,9 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "static/"
STATICFILES_DIRS = [
BASE_DIR / "components",
]
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field