
Add Courses

Show code
models.py Code
from django.db import models
from django_countries.fields import CountryField
# Create your models here.
class Institution(models.Model):
CATEGORY_CHOICES = (('Specialization certificate', 'Specialization certificate'),
('Professional certificate', 'Professional certificate'))
category = models.CharField(max_length=50, choices=CATEGORY_CHOICES)
name = models.CharField(max_length=50, unique=True)
def __str__(self):
return self.name
class Certification(models.Model):
name = models.CharField(max_length=250, unique=True)
personal_description = models.TextField(blank=True, null=True)
description = models.TextField()
rating = models.FloatField()
web_site = models.URLField()
release_date = models.DateField()
filePath = models.CharField(max_length=250)
offered = models.ForeignKey(Institution, on_delete=models.CASCADE)
upload = models.FileField(blank=True, null=True)
def __str__(self):
return self.name
class Course(models.Model):
name = models.CharField(max_length=250, unique=True)
description = models.TextField()
website = models.CharField(max_length=250, blank=True, null=True)
filePath = models.CharField(max_length=250)
certification_id = models.ForeignKey(
Certification,
on_delete=models.CASCADE
)
upload = models.FileField(upload_to='shared/', blank=True, null=True)
def __str__(self):
return self.name
class Contact(models.Model):
forms.py Code
class CourseForm(forms.ModelForm):
class Meta:
model = Course
fields = '__all__'
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control'}),
'description': forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'Input course description'}),
'website': forms.TextInput(attrs={'class': 'form-control'}),
'filePath': forms.TextInput(attrs={'class': 'form-control'}),
'certification_id': forms.Select(attrs={'class': 'form-control', 'placeholder': 'Select Specialization Name'}),
}
Template Code
Django Engine template
{% extends 'base.html' %}
{% block content %}
{% load static %}
{% load fontawesome_5 %}
{{ STATIC_URL }}
{% load pygmentize %}
{% load crispy_forms_tags %}
<br><br>
<section class="container-section mb-4 mt-8">
<div class="container-fluid">
<div class="row g-0">
<div class="portfolio-box-caption">
<div class="row">
<div class="col-1"><img src="{% static 'img/worldwide.gif' %}" alt="Skills"></div>
<div class="col">
<h2 class="portfolio-box-headers" style="text-align:center">
Add Courses</h2>
</div>
</div>
</div>
<hr>
<div class="container border p-3 mb-3 bg-light text-dark" id="specialization">
<form action="" method="POST">
{% csrf_token %}
<div class="form-group row mt-8">
<div class="col-md-6 mb-0">
{{ form.name|as_crispy_field }}
</div>
<div class="col-md-6 mb-0">
{{ form.certification_id|as_crispy_field }}
</div>
</div>
<div class="form-row">
{{ form.description|as_crispy_field }}
</div>
<div class="form-group row mt-8">
<div class="col-md-3 mb-0">
{{ form.website|as_crispy_field }}
</div>
<div class="col-md-3 mb-0">
{{ form.upload|as_crispy_field }}
</div>
<div class="col-md-3 mb-0">
{{ form.filePath|as_crispy_field }}
</div>
</div>
{% if user.is_authenticated %}
<div class="d-grid col-6">
<button type="submit" id="btn-enviar" class="btn btn-warning btn-lg">Enviar</button>
</div>
{% endif %}
</form>
</div>
</div>
</div>
</section>
<section class="container-section mb-4 mt-8">
<div class="container-fluid">
<div class="row g-0">
<div class="portfolio-box-caption">
<div class="row">
<div class="col-1"><img src="{% static 'img/worldwide.gif' %}" alt="Skills"></div>
<div class="col">
<h2 class="portfolio-box-headers" style="text-align:center">
Show code</h2>
</div>
</div>
</div>
<hr>
<div class="container mb-4">
<div class="row mb-4">
<div class="col-sm-6 col-xs-12">
<h4>models.py Code</h4>
<div class="sourcecode">
{{ models|pygmentize:"python3" }}
</div>
</div>
<div class="col-sm-6 col-xs-12">
<h4>forms.py Code</h4>
<div class="sourcecode">
{{ forms|pygmentize:"python3" }}
</div>
</div>
</div>
<hr>
<div class="row">
<h4>Template Code</h4>
<p>Django Engine template</p>
<div class="sourcecode">
{{ template|pygmentize:"html" }}
</div>
</div>
</div>
</div>
</div>
</section>
{% endblock %}