BES-33 Add functions for displaying notes + basic html example
This commit is contained in:
parent
c120a9d1d1
commit
0d7d286028
44
bestnotes/migrations/0002_note_subject_topic.py
Normal file
44
bestnotes/migrations/0002_note_subject_topic.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Generated by Django 2.2.7 on 2019-12-07 10:44
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('bestnotes', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Subject',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=30)),
|
||||
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bestnotes.StudentProfile')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Topic',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=30)),
|
||||
('add_date', models.DateField()),
|
||||
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bestnotes.Subject')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Note',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=30)),
|
||||
('text', models.TextField()),
|
||||
('add_date', models.DateField()),
|
||||
('topic', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bestnotes.Topic')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
19
bestnotes/migrations/0003_auto_20191207_1056.py
Normal file
19
bestnotes/migrations/0003_auto_20191207_1056.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.7 on 2019-12-07 10:56
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bestnotes', '0002_note_subject_topic'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='note',
|
||||
name='user',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bestnotes.StudentProfile'),
|
||||
),
|
||||
]
|
@ -29,6 +29,14 @@ class Topic(models.Model):
|
||||
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
|
||||
add_date = models.DateField()
|
||||
|
||||
class Note(models.Model):
|
||||
name = models.CharField(max_length=30)
|
||||
text = models.TextField(blank=False)
|
||||
topic = models.ForeignKey(Topic, on_delete=models.SET_NULL, null=True)
|
||||
user = models.ForeignKey(StudentProfile, on_delete=models.CASCADE)
|
||||
add_date = models.DateField()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
12
bestnotes/templates/test.html
Normal file
12
bestnotes/templates/test.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% for note in notes%}
|
||||
|
||||
{{ note.name }}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
12
bestnotes/templates/testid.html
Normal file
12
bestnotes/templates/testid.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% for note in notes%}
|
||||
|
||||
{{ note.name }}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
@ -7,4 +7,6 @@ urlpatterns = [
|
||||
path('accounts/', include("django.contrib.auth.urls")),
|
||||
path('subject/', views.subject, name="subject"),
|
||||
path('subject/<id>', views.subject_id, name="subjectid"),
|
||||
path('notes/', views.notes_all, name="notes"),
|
||||
path('notes/<subject_name>', views.notes_name, name="notes_name")
|
||||
]
|
@ -1,5 +1,5 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
from bestnotes.models import Note
|
||||
# Create your views here.
|
||||
|
||||
from django.http import HttpResponse
|
||||
@ -15,3 +15,20 @@ def subject(request):
|
||||
|
||||
def subject_id(request,id):
|
||||
return render(request, "subject.html", {'id': id})
|
||||
|
||||
#Give all notes connected with subject name and pass it to html
|
||||
def notes_name(request,subject_name):
|
||||
all_notes = Note.objects.all()
|
||||
subject_notes = all_notes.filter(topic__subject__name=subject_name) #Get all notes with subject name
|
||||
context = {
|
||||
'notes' : subject_notes
|
||||
}
|
||||
#Change website here
|
||||
return render(request, "test.html", context)
|
||||
|
||||
def notes_all(request):
|
||||
all_notes = Note.objects.all()
|
||||
context = {
|
||||
'notes' : all_notes
|
||||
}
|
||||
return render(request, "test.html", context)
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in New Issue
Block a user