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

Убрал ошибку с нахождением pk в форме создания урока. Доработал работу с файлом

parent 2dbf564e
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('webapp.urls')), path('', include('webapp.urls')),
path('accounts/', include('accounts.urls')) path('accounts/', include('accounts.urls'))
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file
...@@ -11,4 +11,4 @@ class CourseForm(forms.ModelForm): ...@@ -11,4 +11,4 @@ class CourseForm(forms.ModelForm):
class ClassForm(forms.ModelForm): class ClassForm(forms.ModelForm):
class Meta: class Meta:
model = Class model = Class
fields = ['title', 'description', 'file'] fields = ['title', 'description', 'file']
\ No newline at end of file
...@@ -38,6 +38,9 @@ class Class(models.Model): ...@@ -38,6 +38,9 @@ class Class(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
def get_absolute_url(self):
return reverse("webapp:course_detail", args=[str(self.id)])
class Meta: class Meta:
verbose_name = "Class" verbose_name = "Class"
verbose_name_plural = "Classes" verbose_name_plural = "Classes"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<hr> <hr>
<h1>Create new Class</h1> <h1>Create new Class</h1>
<div class='column-center'> <div class='column-center'>
<form action="{% url "webapp:class_create" %}" method="POST"> <form action="{% url "webapp:class_create" course_pk %}" method="POST" enctype="multipart/form-data">
{% include "partial/create_form.html" with button_text="Create new class" %} {% include "partial/create_form.html" with button_text="Create new class" %}
</form> </form>
</div> </div>
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
<a class="p-2" href="{% url 'webapp:course_delete' course.id %}"> <i class="fas fa-trash-alt"></i> </a> <a class="p-2" href="{% url 'webapp:course_delete' course.id %}"> <i class="fas fa-trash-alt"></i> </a>
</div> </div>
<div class="card-body" style="height: 200px;"> <div class="card-body" style="height: 200px;">
<div class='topic-name' style="height: 50px;">
<a class="card-title" href="{% url 'webapp:course_detail' course.id %}"> <h5>{{course.title}}</h5> </a> <a class="card-title" href="{% url 'webapp:course_detail' course.id %}"> <h5>{{course.title}}</h5> </a>
<p class="card-text"> {{ course.description|truncatewords:30 }} </p> </div>
<p class="card-text"> <b>Teacher:</b> {{course.teacher}} </p> <p class="card-text"> <b>Teacher:</b> {{course.teacher}} </p>
<p class="card-text"> <b>Groups(s):</b> <p class="card-text"> <b>Groups(s):</b>
{% for group in course.group.all %} {{group}} {% endfor %} {% for group in course.group.all %} {{group}} {% endfor %}
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<a href="{% url "webapp:courses_list" %}">Return to the main page..</a> <a href="{% url "webapp:courses_list" %}">Return to the main page..</a>
<hr> <hr>
<h1>Create new Course</h1> <h1>Create new Course</h1>
{{course}}
<div class='column-center'> <div class='column-center'>
<form action="{% url "webapp:course_create" %}" method="POST"> <form action="{% url "webapp:course_create" %}" method="POST">
{% include "partial/create_form.html" with button_text="Create new course" %} {% include "partial/create_form.html" with button_text="Create new course" %}
......
...@@ -19,19 +19,19 @@ ...@@ -19,19 +19,19 @@
</blockquote> </blockquote>
</div> </div>
<div style="width: 150px; height: 70px; margin: 20px;"> <div style="width: 150px; height: 70px; margin: 20px;">
<a class='btn btn-primary' href="{% url "webapp:class_create" %}"> Create new week </a> <a class='btn btn-primary' href="{% url "webapp:class_create" course.id %}"> Create new week </a>
</div> </div>
</div> </div>
</div> </div>
{% for class in course.courses.all %} {% for class in course.courses.all %}
<div class="card border-dark mb-3" style="max-width: 100%; height: 240px; margin: 15px auto;"> <div class="card border-dark mb-3" style="max-width: 100%; height: 260px; margin: 15px auto;">
<div class="card-header"> <div class="card-header">
<h6 style="color: #3A63A7;"> Week #{{forloop.counter}} </h6> <h6 style="color: #3A63A7;"> Week #{{forloop.counter}} </h6>
</div> </div>
<div class="card-body text-dark"> <div class="card-body text-dark">
<h5 class="card-title">Topic: {{ class.title }} </h5> <h5 class="card-title">Topic: {{ class.title }} </h5>
<p class="card-text"> Description: {{ class.description }} </p> <p class="card-text"> Description: {{ class.description }} </p>
{{ class.file }} <a href="{{ class.file.url }}"> See the lecture </a>
<hr> <hr>
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p> <p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p>
</div> </div>
......
...@@ -10,5 +10,5 @@ urlpatterns = [ ...@@ -10,5 +10,5 @@ urlpatterns = [
path('course/new/', webapp_views.CourseCreateView.as_view(), name='course_create'), path('course/new/', webapp_views.CourseCreateView.as_view(), name='course_create'),
path('course/<int:pk>/edit/', webapp_views.CourseEditView.as_view(), name='course_edit'), path('course/<int:pk>/edit/', webapp_views.CourseEditView.as_view(), name='course_edit'),
path('courses/class/new', webapp_views.CreateClassView.as_view(), name='class_create') path('course/<int:course_pk>/class/new', webapp_views.CreateClassView.as_view(), name='class_create')
] ]
\ No newline at end of file
...@@ -12,17 +12,17 @@ class CreateClassView(LoginRequiredMixin, PermissionRequiredMixin, CreateView): ...@@ -12,17 +12,17 @@ class CreateClassView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
fields = ['title', 'description', 'file'] fields = ['title', 'description', 'file']
template_name = 'classes/create.html' template_name = 'classes/create.html'
permission_required = 'webapp.add_class' permission_required = 'webapp.add_class'
def get_context_data(self,**kwargs):
kwargs['course_pk']=self.kwargs.get('course_pk')
return super().get_context_data(**kwargs)
def form_valid(self, form): def form_valid(self, form):
course_pk = self.kwargs.get('pk') course_pk = self.kwargs.get('course_pk')
course = get_object_or_404(Course, pk=course_pk) course = get_object_or_404(Course, pk=course_pk)
classweek = form.save(commit=False) classweek = form.save()
classweek.course = classweek course.courses.add(classweek)
classweek.save()
return redirect("webapp:course_detail", course_pk=course.pk) return redirect("webapp:course_detail", course_pk=course.pk)
def get_success_url(self):
return reverse("webapp:course_detail", kwargs = {'project_pk': self.object.course.pk})
class EditClassView(UpdateView): class EditClassView(UpdateView):
......
...@@ -13,7 +13,7 @@ class CourseCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView): ...@@ -13,7 +13,7 @@ class CourseCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
template_name = 'courses/create.html' template_name = 'courses/create.html'
form_class = CourseForm form_class = CourseForm
model = Course model = Course
pk_url_kwarg = 'project_pk' pk_url_kwarg = 'course_pk'
permission_required = 'webapp.add_course' permission_required = 'webapp.add_course'
def get_form(self, form_class=None): def get_form(self, form_class=None):
......
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