伙计们,我目前正在注册课程,每门课程都有12个名额
这里image
当用户注册任何课程时,应将其计算在内
我的views.py
文件
def register_course(request):
if request.method == 'POST':
form = UserRegisterForCourse(request.POST)
if form.is_valid():
form.save()
select_course = form.cleaned_data.get('select_course')
messages.success(request, f'You have been successfully registered for {select_course}')
return redirect('blog-home')
else:
form = UserRegisterForCourse()
return render(request, 'blog/register_course.html', {'form':form})
models.py
class RegisterForCourse(models.Model):
name = models.CharField(max_length=50)
COURSE_CHOICES = (
('Python', 'Python'),
('Java', 'Java'),
('JavaScript', 'JavaScript'),
('C#', 'C#'),
('C++', 'C++'),
('Web', 'Web'),
)
select_course = models.CharField(max_length=10, choices=COURSE_CHOICES)
phone = models.CharField(max_length=13)
def __str__(self):
return self.select_course
和模板文件
<div class="content-section">
<h3>Register for courses</h3>
<p class='text-muted'>Very few places left</p>
<ul class="list-group">
<li class="list-group-item list-group-item-light">Python
<div class="float-right">
<div class="my-progress" data-count="2"><div></div></div> <span>2</span>/12
</div>
</li>
<li class="list-group-item list-group-item-light">Java
<div class="float-right">
<div class="my-progress" data-count="12"><div></div></div> <span>5</span>/12
</div>
</li>
<li class="list-group-item list-group-item-light">JavaScript
<div class="float-right">
<div class="my-progress" data-count="7"><div></div></div> <span>7</span>/12
</div>
</li>
<li class="list-group-item list-group-item-light">C#
<div class="float-right">
<div class="my-progress" data-count="8"><div></div></div> <span>8</span>/12
</div>
</li>
<li class="list-group-item list-group-item-light">C++
<div class="float-right">
<div class="my-progress" data-count="8"><div></div></div> <span>8</span>/12
</div>
</li>
<li class="list-group-item list-group-item-light">Web
<div class="float-right">
<div class="my-progress" data-count="8"><div></div></div> <span>8</span>/12
</div>
</li>
</ul>
</div>
我无法执行此过程,您能帮我吗?现在我正在使用sqlite数据库,但我尚未添加数据库。根据用户的选择,“课程”字段是一个选择选项,进度条应正确进行。
先谢谢您!感谢您的帮助