Commit dd71938d authored by Борис Ким's avatar Борис Ким

Добавил паршиалы для форм, создал вью для создания нового курса

parent 0c285252
asgiref==3.4.1 asgiref==3.4.1
Django==3.2.8 Django==3.2.8
django-crispy-forms==1.13.0
pytz==2021.3 pytz==2021.3
sqlparse==0.4.2 sqlparse==0.4.2
...@@ -27,7 +27,8 @@ INSTALLED_APPS = [ ...@@ -27,7 +27,8 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'webapp' 'webapp',
'crispy_forms'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -122,4 +123,6 @@ STATICFILES_DIRS = [ ...@@ -122,4 +123,6 @@ STATICFILES_DIRS = [
] ]
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
\ No newline at end of file
CRISPY_TEMPLATE_PACK = 'bootstrap4'
\ No newline at end of file
...@@ -21,5 +21,6 @@ urlpatterns = [ ...@@ -21,5 +21,6 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', webapp_views.CoursesListView.as_view(), name='courses_list'), path('', webapp_views.CoursesListView.as_view(), name='courses_list'),
path('course/<int:course_pk>/', webapp_views.CourseDetailView.as_view(), name='course_detail'), path('course/<int:course_pk>/', webapp_views.CourseDetailView.as_view(), name='course_detail'),
path('course/<int:pk>/delete', webapp_views.CourseDeleteView.as_view(), name='course_delete') path('course/<int:pk>/delete/', webapp_views.CourseDeleteView.as_view(), name='course_delete'),
path('course/new/', webapp_views.CourseCreateView.as_view(), name='course_create')
] ]
from django import forms
from .models import Course
class CourseForm(forms.ModelForm):
class Meta:
model = Course
fields = ['title', 'description', 'group', 'teacher', 'start_date']
\ No newline at end of file
from django.db import models from django.db import models
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.urls import reverse
# class Student(User): # class Student(User):
...@@ -28,6 +29,10 @@ class Course(models.Model): ...@@ -28,6 +29,10 @@ class Course(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
def get_absolute_url(self):
return reverse("course_detail", args=[str(self.id)])
class Group(models.Model): class Group(models.Model):
group_name = models.CharField(max_length=50, verbose_name='group_name') group_name = models.CharField(max_length=50, verbose_name='group_name')
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</nav> </nav>
<div class="row d-flex"> <div class="row d-flex">
<div class="sidebar col-2"> <div class="sidebar col-2">
<a href="#about">Dashboard</a> <a href="{% url 'course_create' %}">Create new Course </a>
<a href="#services">Button 1</a> <a href="#services">Button 1</a>
<a href="#clients">Button 2</a> <a href="#clients">Button 2</a>
<a href="#contact">Button 3</a> <a href="#contact">Button 3</a>
......
...@@ -3,17 +3,20 @@ ...@@ -3,17 +3,20 @@
{% block title %} List {% endblock %} {% block title %} List {% endblock %}
{% block content %} {% block content %}
<div class='course-container row d-flex flex-wrap justify-content-between'> <div class='course-container row d-flex flex-wrap justify-content-start'>
{% for course in courses %} {% for course in courses %}
<div class="content-course col-4" style="width: 300px;"> <div class="content-course col-4" style="width: 300px;">
<div class="block-course"> <div class="block-course">
<div class="card-header"> <div class="card-header">
Course Course
</div> </div>
<div class="card-body"> <div class="card-body" style="height: 150px;">
<h5 class="card-title"> {{course.title}} </h5> <h5 class="card-title"> {{course.title}} </h5>
<p class="card-text"> {{course.description}} </p> <p class="card-text"> {{course.description}} </p>
</div>
<div class="card-buttons" style="text-align: center;">
<a class="btn btn-primary" href="{% url 'course_detail' course.id %}"> See more </a> <a class="btn btn-primary" href="{% url 'course_detail' course.id %}"> See more </a>
<a class="btn btn-info" href="#"> Edit </a>
<a class="btn btn-danger" href="{% url 'course_delete' course.id %}"> Delete </a> <a class="btn btn-danger" href="{% url 'course_delete' course.id %}"> Delete </a>
</div> </div>
</div> </div>
......
{% extends "base.html" %}
{% block title %} Create new Course {% endblock %}
{% block content %}
<a href="{% url "courses_list" %}">Return to the main page..</a>
<hr>
<h1>Create new Course</h1>
<div class='column-center'>
<form action="{% url "course_create" %}" method="POST">
{% include "partial/create_form.html" with button_text="Create new course" %}
</form>
</div>
<hr>
{% endblock %}
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
{% block title %} {{course.title}} {% endblock %} {% block title %} {{course.title}} {% endblock %}
{% block content %} {% block content %}
<a href="{% url "courses_list" %}"> << Return to the main page..</a>
<hr>
<div class='course-block-detail'> <div class='course-block-detail'>
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
...@@ -10,13 +12,14 @@ ...@@ -10,13 +12,14 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<blockquote class="blockquote mb-0"> <blockquote class="blockquote mb-0">
<p>Gain the job-ready skills you need to launch your career in IT Support, Data Analytics, UX Design or Project Management. Prepare for an entry-level job as a data analyst. <p>
In this program, you’ll learn how to collect, transform, and organize data in order to help draw new insights and make informed business decisions. {{ course.description }}
This is for you if you enjoy working with numbers, uncovering trends, and visualizations.
</p> </p>
<footer class="blockquote-footer"> Pr. {{course.teacher}} </footer> <footer class="blockquote-footer"> Pr. {{course.teacher}} </footer>
</blockquote> </blockquote>
</div> </div>
</div> </div>
</div> </div>
<hr>
<a href="{% url "courses_list" %}"> << Return to the main page..</a>
{% endblock %} {% endblock %}
\ No newline at end of file
{% csrf_token %}
{% load crispy_forms_filters %}
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
{% for field in form %}
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{% for error in field.errors %}
<p style='color: red'>{{ error }}</p>
{% endfor %}
{% endfor %}
<p>{{ form|crispy }}</p>
<button>{{ button_text }}</button>
...@@ -5,6 +5,18 @@ from django.views.generic import ListView, CreateView, UpdateView, DetailView, D ...@@ -5,6 +5,18 @@ from django.views.generic import ListView, CreateView, UpdateView, DetailView, D
from webapp.models import Course from webapp.models import Course
from webapp.forms import CourseForm
class CourseCreateView(CreateView):
template_name = 'courses/create.html'
form_class = CourseForm
model = Course
pk_url_kwarg = 'project_pk'
def get_form(self, form_class=None):
form = super().get_form()
return form
class CoursesListView(ListView): class CoursesListView(ListView):
...@@ -26,3 +38,5 @@ class CourseDeleteView(DeleteView): ...@@ -26,3 +38,5 @@ class CourseDeleteView(DeleteView):
success_url = reverse_lazy('courses_list') success_url = reverse_lazy('courses_list')
class CourseEditView(UpdateView):
pass
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment