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

Truekorsar t #934

Open
wants to merge 12 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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
*.pyo
*~
.idea/
__pycache__
venv/
1 change: 0 additions & 1 deletion README.md

This file was deleted.

Empty file added Text Document.txt
Empty file.
Empty file added coaches/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions coaches/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from .models import Coach

class CoachAdmin(admin.ModelAdmin):
list_display=('first_name','last_name',
'gender','skype','description')
list_filter=('user__is_staff',)
admin.site.register(Coach,CoachAdmin)
5 changes: 5 additions & 0 deletions coaches/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CoachesConfig(AppConfig):
name = 'coaches'
34 changes: 34 additions & 0 deletions coaches/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 2.2.5 on 2019-11-17 14:53

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Coach',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_of_birth', models.DateField(auto_now=True, verbose_name='краткое описание')),
('gender', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=30, verbose_name='пол')),
('phone', models.CharField(max_length=30, verbose_name='телефон')),
('adress', models.CharField(max_length=30, verbose_name='адресс')),
('skype', models.CharField(max_length=30, verbose_name='skype')),
('description', models.TextField(max_length=30, verbose_name='описание')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='пользователь')),
],
options={
'verbose_name': 'Тренер',
'verbose_name_plural': 'Тренеры',
},
),
]
18 changes: 18 additions & 0 deletions coaches/migrations/0002_auto_20191204_2138.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.5 on 2019-12-04 18:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('coaches', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='coach',
name='date_of_birth',
field=models.DateField(verbose_name='краткое описание'),
),
]
Empty file added coaches/migrations/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions coaches/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import models
from django.contrib.auth.models import User

class Coach(models.Model):
user=models.OneToOneField(User,on_delete=models.CASCADE,
verbose_name='пользователь')
date_of_birth=models.DateField(auto_now=False,verbose_name='краткое описание')
gender=models.CharField(max_length=30,verbose_name='пол',choices=(
('M','Male'),
('F','Female'),
))
phone=models.CharField(max_length=30,verbose_name='телефон')
adress=models.CharField(max_length=30,verbose_name='адресс')
skype=models.CharField(max_length=30,verbose_name='skype')
description=models.TextField(max_length=30,verbose_name='описание')


class Meta:
verbose_name_plural='Тренеры'
verbose_name='Тренер'

def __str__(self):
return self.user.first_name
def first_name(self):
return str(self.user.first_name)
def last_name(self):
return str(self.user.last_name)

64 changes: 64 additions & 0 deletions coaches/templates/coaches/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends "navbar.html" %}
{% load static %}
{% block title %}{{coach.last_name}}{% endblock %}
{% block main %}"nav-link" href="/">{% endblock %}
{% block content %}
<h2>{{coach.first_name}} {{coach.last_name}}</h2>
<table class="table table-striped">
<tbody>
<tr>
<th scope="row">Дата рождения</th>
<td></td>
<td></td>
<td>{{coach.date_of_birth|date:"j E, Y"}}</td>
</tr>
<tr>
<th scope="row">Адрес</th>
<td></td>
<td></td>
<td>{{coach.adress}}</td>
</tr>
<tr>
<th scope="row">Почта</th>
<td></td>
<td></td>
<td>{{coach.user.email}}</td>
</tr>
<tr>
<th scope="row">Skype</th>
<td></td>
<td></td>
<td>{{coach.skype}}</td>
</tr>
<tr>
<th scope="row">Телефон</th>
<td></td>
<td></td>
<td>{{coach.phone}}</td>
</tr>
<tr>
<th scope="row">Курсы учитель</th>
<td></td>
<td></td>
<td>
{% for course in courses_coach %}
<a href="{% url 'by_course' course.pk %}">{{course.name}}</a>
<a href="{% url 'student_list' %}?course_id={{course.pk}}"><img src="{% static "icon.png" %}"></a>
{% endfor %}
</td>
</tr>
<tr>
<th scope="row">Курсы ассистент</th>
<td></td>
<td></td>
<td>
{% for course in courses_assistant %}
<a href="{% url 'by_course' course.pk %}">{{course.name}}</a>
<a href="{% url 'student_list' %}?course_id={{course.pk}}"><img src="{% static "icon.png" %}"></a>
{% endfor %}

</td>
</tr>
</tbody>
</table>
{% endblock %}
3 changes: 3 additions & 0 deletions coaches/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions coaches/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from django.urls import path,include
from .views import *

urlpatterns = [
path('<int:coach_id>', detail,name='by_coach'),

]
8 changes: 8 additions & 0 deletions coaches/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.shortcuts import render
from .models import Coach

def detail(request,coach_id):
coach=Coach.objects.get(pk=coach_id)
context={'coach':coach,'courses_coach':coach.coach_courses.all(),
'courses_assistant':coach.assistant_courses.all()}
return render(request,'coaches/detail.html',context)
Empty file added courses/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions courses/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Course,Lesson

admin.site.register(Course)
admin.site.register(Lesson)
5 changes: 5 additions & 0 deletions courses/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CoursesConfig(AppConfig):
name = 'courses'
13 changes: 13 additions & 0 deletions courses/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.forms import ModelForm

from .models import Course,Lesson

class CourseModelForm(ModelForm):
class Meta:
model=Course
fields=('name','short_description','description','coach','assistant')

class LessonModelForm(ModelForm):
class Meta:
model=Lesson
fields=('subject','course','description','order')
34 changes: 34 additions & 0 deletions courses/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 2.2.5 on 2019-11-08 14:04

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, verbose_name='название')),
('short_description', models.CharField(blank=True, max_length=20, null=True, verbose_name='краткое описание')),
('description', models.TextField(verbose_name='полное описание')),
],
),
migrations.CreateModel(
name='Lesson',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('subject', models.CharField(max_length=30, verbose_name='тема')),
('description', models.TextField(verbose_name='описание')),
('order', models.PositiveIntegerField(verbose_name='номер по порядку')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='courses.Course')),
],
),
]
33 changes: 33 additions & 0 deletions courses/migrations/0002_auto_20191117_1753.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.2.5 on 2019-11-17 14:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('coaches', '0001_initial'),
('courses', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='course',
options={'verbose_name': 'Курс', 'verbose_name_plural': 'Курсы'},
),
migrations.AlterModelOptions(
name='lesson',
options={'ordering': ['order'], 'verbose_name': 'Урок', 'verbose_name_plural': 'Уроки'},
),
migrations.AddField(
model_name='course',
name='assistant',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='assistant_courses', to='coaches.Coach', verbose_name='помощник'),
),
migrations.AddField(
model_name='course',
name='coach',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='coach_courses', to='coaches.Coach', verbose_name='тренер'),
),
]
19 changes: 19 additions & 0 deletions courses/migrations/0003_auto_20191204_2138.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.5 on 2019-12-04 18:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('courses', '0002_auto_20191117_1753'),
]

operations = [
migrations.AlterField(
model_name='lesson',
name='course',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Course', verbose_name='курс'),
),
]
Empty file added courses/migrations/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions courses/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.db import models
from coaches.models import Coach


class Course(models.Model):
name=models.CharField(max_length=50,verbose_name='название')
short_description=models.CharField(max_length=20,null=True,blank=True,
verbose_name='краткое описание')
description=models.TextField(verbose_name='полное описание')
coach=models.ForeignKey(Coach,on_delete=models.CASCADE,
related_name='coach_courses',verbose_name='тренер',
null=True,blank=True)
assistant=models.ForeignKey(Coach,on_delete=models.CASCADE,
related_name='assistant_courses',
verbose_name='помощник',null=True,blank=True)



class Meta:
verbose_name_plural='Курсы'
verbose_name='Курс'

def __str__(self):
return self.name


class Lesson(models.Model):
subject=models.CharField(max_length=30,verbose_name='тема')
course=models.ForeignKey(Course,on_delete=models.CASCADE,
verbose_name='курс')
description=models.TextField(verbose_name='описание')
order=models.PositiveIntegerField(verbose_name='номер по порядку')

class Meta:
verbose_name_plural='Уроки'
verbose_name='Урок'
ordering=['order']

def __str__(self):
return self.subject

14 changes: 14 additions & 0 deletions courses/templates/courses/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "navbar.html" %}

{% block title %}Добавление{% endblock %}
{% block main %}"nav-link" href="/">{% endblock %}
{% block content %}

<h2>Добавление новой записи</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" vаluе="Добавить">
</form>

{% endblock %}
14 changes: 14 additions & 0 deletions courses/templates/courses/add_lesson.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "navbar.html" %}

{% block title %}Добавление{% endblock %}
{% block main %}"nav-link" href="/">{% endblock %}
{% block content %}

<h2>{{title}}</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" vаluе="Добавить">
</form>

{% endblock %}
Loading