Templates and Admin personalization
This commit is contained in:
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Python Debugger: Django",
|
||||||
|
"type": "debugpy",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/techdb/manage.py",
|
||||||
|
"args": ["runserver"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"django": true,
|
||||||
|
"justMyCode": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,29 +1,55 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
import nested_admin
|
import nested_admin
|
||||||
|
from django import forms
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
class TrainingForm(forms.ModelForm):
|
||||||
|
model=Training
|
||||||
|
|
||||||
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
|
form = super().get_form(request, obj, **kwargs)
|
||||||
|
form.base_fields['mission'].widget.can_add_related = False
|
||||||
|
form.base_fields['mission'].widget.can_delete_related = False
|
||||||
|
form.base_fields['mission'].widget.can_change_related = False
|
||||||
|
print("pluto")
|
||||||
|
return form
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
class HourBuildingLegInline(nested_admin.NestedTabularInline):
|
class HourBuildingLegInline(nested_admin.NestedTabularInline):
|
||||||
model = HourBuildingLeg
|
model = HourBuildingLeg
|
||||||
extra = 1
|
extra = 0
|
||||||
fk_name = 'hb'
|
fk_name = 'hb'
|
||||||
|
|
||||||
class HourBuildingInLine(nested_admin.NestedTabularInline):
|
class HourBuildingInLine(nested_admin.NestedTabularInline):
|
||||||
model = HourBuilding
|
model = HourBuilding
|
||||||
extra = 1
|
extra = 0
|
||||||
inlines = [HourBuildingLegInline]
|
inlines = [HourBuildingLegInline]
|
||||||
fk_name = 'weekpref'
|
fk_name = 'weekpref'
|
||||||
|
verbose_name_plural = "Hour Building"
|
||||||
|
max_num = 7
|
||||||
|
|
||||||
class TrainingInLIne(nested_admin.NestedTabularInline):
|
class TrainingInLIne(nested_admin.NestedTabularInline):
|
||||||
model = Training
|
model = Training
|
||||||
extra = 0
|
form = TrainingForm
|
||||||
|
extra = 1
|
||||||
fk_name = 'weekpref'
|
fk_name = 'weekpref'
|
||||||
|
verbose_name_plural = "Training Missions"
|
||||||
|
max_num = 7
|
||||||
|
|
||||||
|
def get_formset(self, request, obj=None, **kwargs):
|
||||||
|
formset = super(TrainingInLIne, self).get_formset(request, obj=None, **kwargs)
|
||||||
|
return formset
|
||||||
|
|
||||||
class WeekPreferenceAdmin(nested_admin.NestedModelAdmin):
|
class WeekPreferenceAdmin(nested_admin.NestedModelAdmin):
|
||||||
list_display = ('week', 'student')
|
|
||||||
list_filter = ['week', 'student']
|
|
||||||
inlines = [TrainingInLIne, HourBuildingInLine]
|
inlines = [TrainingInLIne, HourBuildingInLine]
|
||||||
|
|
||||||
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
|
form: forms.Form = super().get_form(request, obj, **kwargs)
|
||||||
|
form.base_fields['student'].widget.can_add_related = False
|
||||||
|
form.base_fields['student'].widget.can_delete_related = False
|
||||||
|
form.base_fields['student'].widget.can_change_related = False
|
||||||
|
return form
|
||||||
|
|
||||||
class StudentAdmin(admin.ModelAdmin):
|
class StudentAdmin(admin.ModelAdmin):
|
||||||
list_display = ("surname", "name", "course", "email","active")
|
list_display = ("surname", "name", "course", "email","active")
|
||||||
list_filter = ["course", "active"]
|
list_filter = ["course", "active"]
|
||||||
|
|||||||
@@ -75,14 +75,16 @@ class WeekPreference(models.Model):
|
|||||||
null=False,
|
null=False,
|
||||||
db_index=True,
|
db_index=True,
|
||||||
default=ExtractWeek(Now()) + 1,
|
default=ExtractWeek(Now()) + 1,
|
||||||
auto_created=True
|
auto_created=True,
|
||||||
|
verbose_name="Week Number"
|
||||||
)
|
)
|
||||||
|
|
||||||
student = models.ForeignKey(
|
student = models.ForeignKey(
|
||||||
Student,
|
Student,
|
||||||
null=False,
|
null=False,
|
||||||
db_index=True,
|
db_index=True,
|
||||||
on_delete=models.DO_NOTHING
|
on_delete=models.DO_NOTHING,
|
||||||
|
verbose_name="Student Selection"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -105,12 +107,14 @@ class MissionProfile(models.Model):
|
|||||||
mtype = models.CharField(
|
mtype = models.CharField(
|
||||||
null=False,
|
null=False,
|
||||||
default=MissionType.PPL,
|
default=MissionType.PPL,
|
||||||
choices=MissionType
|
choices=MissionType,
|
||||||
|
verbose_name="Mission Type"
|
||||||
)
|
)
|
||||||
|
|
||||||
mnum = models.PositiveSmallIntegerField(
|
mnum = models.PositiveSmallIntegerField(
|
||||||
null=True,
|
null=True,
|
||||||
default=0
|
default=0,
|
||||||
|
verbose_name="Mission Number"
|
||||||
)
|
)
|
||||||
|
|
||||||
duration = models.DurationField(
|
duration = models.DurationField(
|
||||||
|
|||||||
BIN
techdb/static/cantorair.jpg
Normal file
BIN
techdb/static/cantorair.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
@@ -38,7 +39,6 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'nested_admin',
|
'nested_admin',
|
||||||
'catops',
|
|
||||||
'flightslot'
|
'flightslot'
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ ROOT_URLCONF = 'techdb.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [os.path.join(BASE_DIR, 'templates/')],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@@ -72,6 +72,9 @@ TEMPLATES = [
|
|||||||
|
|
||||||
WSGI_APPLICATION = 'techdb.wsgi.application'
|
WSGI_APPLICATION = 'techdb.wsgi.application'
|
||||||
|
|
||||||
|
STATICFILES_DIRS = [
|
||||||
|
os.path.join(BASE_DIR, "static"),
|
||||||
|
]
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||||
|
|||||||
@@ -20,3 +20,7 @@ from django.urls import path
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
admin.site.site_header = "CantorAir Flight Scheduler"
|
||||||
|
admin.site.site_title = "CantorAir Flight Scheduler"
|
||||||
|
admin.site.index_title = "Welcome to CantorAir Flight Scheduler Portal"
|
||||||
22
techdb/templates/admin/base_site.html
Normal file
22
techdb/templates/admin/base_site.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{% extends "admin/base.html" %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
|
||||||
|
|
||||||
|
{% block branding %}
|
||||||
|
|
||||||
|
<h1 id="site-name">
|
||||||
|
<a href="{% url 'admin:index' %}">
|
||||||
|
<img src="{% static 'cantorair.jpg' %}" height="60px" />
|
||||||
|
</a>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></div>
|
||||||
|
{% if user.is_anonymous %}
|
||||||
|
{% include "admin/color_theme_toggle.html" %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block nav-global %}{% endblock %}
|
||||||
Reference in New Issue
Block a user