update classroom/views
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Classroom
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(Classroom)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 3.1.3 on 2020-11-10 13:03
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('classroom', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='classroom',
|
||||
name='users',
|
||||
field=models.ManyToManyField(related_name='users', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
@@ -9,6 +9,12 @@ class Classroom(models.Model):
|
||||
description = models.TextField(max_length=300)
|
||||
created_by = models.ForeignKey(User, on_delete=models.PROTECT)
|
||||
created_at = models.DateTimeField(default=timezone.now)
|
||||
users = models.ManyToManyField(User,related_name='users')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %} Home {% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<!-- Page Heading -->
|
||||
<h1 class="h3 mb-4 text-gray-800">Classrooms</h1>
|
||||
<!-- ROW -->
|
||||
<div class="row">
|
||||
<!-- COL -->
|
||||
{% for classroom in classrooms %}
|
||||
<div class="col-lg-3 col-md-4 col-sm-1">
|
||||
<!-- CARD -->
|
||||
<div class="card border-bottom-primary shadow mb-4">
|
||||
<div class="card-header py-3">
|
||||
<a href="#!">
|
||||
<h6 class="m-0 font-weight-bold text-primary">{{ classroom.name }}</h6>
|
||||
</a>
|
||||
</div>
|
||||
<a href="#!">
|
||||
<div class="card-body">
|
||||
<div class="text-center">
|
||||
<img class="img-fluid px-3 px-sm-4 mt-3 mb-4" style="width: 25rem;" src="{% static 'mainapp/img/undraw_posting_photo.svg' %}" alt="">
|
||||
</div>
|
||||
<p class="text-secondary">{{ classroom.description }}</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<!-- END CARD -->
|
||||
</div>
|
||||
<!-- END COL -->
|
||||
{% endfor %}
|
||||
</div>
|
||||
<!-- END ROW -->
|
||||
|
||||
{% endblock content %}
|
||||
@@ -4,5 +4,6 @@ from . import views
|
||||
app_name = 'classroom'
|
||||
|
||||
urlpatterns = [
|
||||
path('home/', views.home, name='home'),
|
||||
path('', views.home, name='home'),
|
||||
path('create/', views.create_classroom, name = 'create_classroom'),
|
||||
]
|
||||
@@ -1,9 +1,39 @@
|
||||
from django.shortcuts import render
|
||||
from .models import Classroom
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def home(requests):
|
||||
classrooms = requests.user.classroom_set.all()
|
||||
print(classrooms)
|
||||
context = {
|
||||
'classrooms' : classrooms,
|
||||
}
|
||||
return render(requests, 'classroom/home.html', context)
|
||||
|
||||
def create_classroom(requests):
|
||||
context = {
|
||||
'title' : 'Classroom',
|
||||
}
|
||||
return render(requests, 'base.html', context)
|
||||
|
||||
def join_classroom(requests):
|
||||
context = {
|
||||
'title' : 'Classroom',
|
||||
}
|
||||
return render(requests, 'base.html', context)
|
||||
|
||||
def open_classroom(requests):
|
||||
context = {
|
||||
'title' : 'Classroom',
|
||||
}
|
||||
return render(requests, 'base.html', context)
|
||||
|
||||
def delete_classroom(requests):
|
||||
context = {
|
||||
'title' : 'Classroom',
|
||||
}
|
||||
return render(requests, 'base.html', context)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<title>OpenClassroom | {{ title }}</title>
|
||||
<title>
|
||||
OpenClassroom | {% block title %}{% endblock %}
|
||||
</title>
|
||||
|
||||
<!-- Custom fonts for this template-->
|
||||
<link href="{% static 'mainapp/vendor/fontawesome-free/css/all.min.css' %}" rel="stylesheet" type="text/css">
|
||||
@@ -38,9 +40,8 @@
|
||||
|
||||
<!-- Begin Page Content -->
|
||||
<div class="container-fluid">
|
||||
<!-- {% block content %}
|
||||
{% endblock content %} -->
|
||||
<h1>Hello World</h1>
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
</div>
|
||||
<!-- /.container-fluid -->
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from classroom.models import Classroom
|
||||
from PIL import Image
|
||||
# Create your models here.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user