Commit 8e62d75a authored by Falk, Dennis Nikolas's avatar Falk, Dennis Nikolas
Browse files

Merge branch 'Dennis_2020_06_12' into 'master'

Dennis 2020 06 12

See merge request !8
parents 0d825f19 08328fb0
/venv/
/.idea/
/djangoblog.sqlite3
/media/uploads/2020/
......@@ -73,8 +73,8 @@ from .models import Blog
def home(request):
blogObjects = Blog.objects().all # grabs all objects from the DB table 'Blog'
return render(request, '<Website e.g. <App folder>/home.html', {'blogobjects':blogobjects})
``` --> damit bekommt man ein QuerySet zurückgegeben
--> damit bekommt man ein QuerySet zurückgegeben
```
**2. home.html**
```
......@@ -83,3 +83,49 @@ def home(request):
{% endfor %}
```
#### CKEditor Befehle
**1. Installation**
```
pip install django-ckeditor
```
**2. Vorbereitende Maßnahmen (schon durchgeführt und nicht nochmal nötig)**
Für CKEditor ohne Uploader
-Add ckeditor to your INSTALLED_APPS setting.
-Run the collectstatic management command:
```
manage.py collectstatic
```
This will copy static CKEditor required media resources into the directory given by the STATIC_ROOT setting.
See Django’s documentation on managing static files for more info.
Zusätzlich für CKEditor mit Uploader
-Add ckeditor_uploader to your INSTALLED_APPS setting.
-Add a CKEDITOR_UPLOAD_PATH setting to the project’s settings.py file. This setting specifies a relative path to
your CKEditor media upload directory. CKEditor uses Django’s storage API. By default, Django uses the file system
storage backend (it will use your MEDIA_ROOT and MEDIA_URL) and if you don’t use a different backend you have to
have write permissions for the CKEDITOR_UPLOAD_PATH path within MEDIA_ROOT, i.e.:
```
CKEDITOR_UPLOAD_PATH = "uploads/"
```
When using default file system storage, images will be uploaded to “uploads” folder in your
MEDIA_ROOT and urls will be created against MEDIA_URL (/media/uploads/image.jpg).
**3. Benutzung**
Field
The quickest way to add rich text editing capabilities to your models is to use the included RichTextField model
field type. A CKEditor widget is rendered as the form field but in all other regards the field behaves as the
standard Django TextField. For example:
```
from django.db import models
from ckeditor.fields import RichTextField
class Post(models.Model):
content = RichTextField()
```
For file upload support use RichTextUploadingField from ckeditor_uploader.fields.
**4. Doc**
Mehr unter: https://django-ckeditor.readthedocs.io/en/latest/#usage
\ No newline at end of file
# Generated by Django 3.0.7 on 2020-06-09 20:42
# Generated by Django 3.0.7 on 2020-06-16 18:21
import ckeditor_uploader.fields
import datetime
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
......@@ -15,16 +19,25 @@ class Migration(migrations.Migration):
name='Blog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('identifier', models.CharField(default=uuid.UUID('c503a3c1-ed2e-47c9-81f7-eb8c2f0103bc'), max_length=500, unique=True)),
('title', models.CharField(default='Titel', max_length=200)),
('description', ckeditor_uploader.fields.RichTextUploadingField(blank=True)),
('date', models.DateTimeField(blank=True, default=datetime.datetime.now)),
('image', models.ImageField(blank=True, upload_to='images/')),
('created', models.DateField(auto_now_add=True)),
('edited', models.DateField(auto_now=True)),
('status', models.IntegerField(default=1)),
('url', models.URLField(blank=True, max_length=300)),
],
),
migrations.CreateModel(
name='Project',
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('description', models.TextField()),
('date', models.DateField()),
('image', models.ImageField(upload_to='portfolio/images/')),
('author', models.TextField(max_length=150)),
('text', models.TextField(max_length=1000)),
('date', models.DateTimeField(default=datetime.datetime.now)),
('related_blog', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='blog.Blog')),
],
),
]
# Generated by Django 3.0.7 on 2020-06-09 21:06
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('blog', '0001_initial'),
]
operations = [
migrations.DeleteModel(
name='Project',
),
migrations.AddField(
model_name='blog',
name='date',
field=models.DateTimeField(blank=True, default=datetime.datetime.now),
),
migrations.AddField(
model_name='blog',
name='description',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='blog',
name='title',
field=models.CharField(default='Titel', max_length=200),
),
]
# Generated by Django 3.0.7 on 2020-06-09 21:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('blog', '0002_auto_20200609_2106'),
]
operations = [
migrations.AddField(
model_name='blog',
name='image',
field=models.ImageField(blank=True, upload_to='images/'),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:13
from django.db import migrations, models
import django.utils.timezone
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0003_blog_image'),
]
operations = [
migrations.AddField(
model_name='blog',
name='created',
field=models.DateField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='blog',
name='edited',
field=models.DateField(auto_now=True),
),
migrations.AddField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('70a33298-78df-43b9-a8ad-865b35c6bfad'), max_length=500, unique=True),
),
migrations.AddField(
model_name='blog',
name='status',
field=models.IntegerField(default=1),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:14
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0004_auto_20200611_1213'),
]
operations = [
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('ac2cc36e-8a2b-4616-be75-d6d5f89e67e6'), max_length=500, unique=True),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:17
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0005_auto_20200611_1214'),
]
operations = [
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('54a497c2-2834-45bf-90ee-51e9cb371b25'), max_length=500, unique=True),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:26
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0006_auto_20200611_1217'),
]
operations = [
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('ffb72471-f1df-46bc-9f49-55b86863537f'), max_length=500, unique=True),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:26
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0007_auto_20200611_1226'),
]
operations = [
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('db0967ff-63bd-4d0f-bbb1-04a87e241d24'), max_length=500, unique=True),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:36
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0008_auto_20200611_1226'),
]
operations = [
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('950b5bcf-2eea-460b-bb81-96a72c504e35'), max_length=500, unique=True),
),
]
# Generated by Django 3.0.7 on 2020-06-11 12:57
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0009_auto_20200611_1236'),
]
operations = [
migrations.AddField(
model_name='blog',
name='url',
field=models.URLField(blank=True, max_length=300),
),
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('28aef679-2488-4988-afdc-4a93b66695f1'), max_length=500, unique=True),
),
]
# Generated by Django 3.0.7 on 2020-06-12 20:42
import datetime
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
('blog', '0010_auto_20200611_1257'),
]
operations = [
migrations.AlterField(
model_name='blog',
name='identifier',
field=models.CharField(default=uuid.UUID('c243d1b6-0415-4836-ba1b-531367c635af'), max_length=500, unique=True),
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('author', models.TextField(max_length=150)),
('text', models.TextField(max_length=1000)),
('date', models.DateTimeField(default=datetime.datetime.now)),
('related_blog', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='blog.Blog')),
],
),
]
import uuid
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models
from datetime import datetime
......@@ -14,7 +16,7 @@ class Blog(models.Model):
"""
identifier = models.CharField(max_length=500, unique=True, default=uuid.uuid4())
title = models.CharField(default="Titel", max_length=200)
description = models.TextField(blank=True)
description = RichTextUploadingField(blank=True)
date = models.DateTimeField(default=datetime.now, blank=True)
# need to install pillow for images
image = models.ImageField(upload_to='images/', blank=True)
......
......@@ -35,7 +35,11 @@
<div class="card-body">
<div class="text-right minidate" >{{ blog.date }}</div>
<h3 class="card-title text-center">{{ blog.title }}</h3>
{% autoescape off %}
<p class="card-text">{{ blog.description }}</p>
{% endautoescape %}
<div id="cardid" class="text-right minidate" >{{ blog.id }}</div>
{% if blog.url %}
<div class="card-footer">
......
......@@ -21,7 +21,11 @@
<div class="container">
{% bootstrap_messages %}
<div class="text-right minidate" >{{ blog.date }}</div>
{% autoescape off %}
<p class="card-text">{{ blog.description }}</p>
{% endautoescape %}
<a href="{% url 'blog:all_blogs' %}" class="btn btn-primary">Back to Blogs</a>
<br>
{% if blog.image and blog.image.url %}
......
......@@ -40,6 +40,8 @@ INSTALLED_APPS = [
'blog',
'portfolio',
'bootstrap4',
'ckeditor',
'ckeditor_uploader',
]
MIDDLEWARE = [
......@@ -123,6 +125,13 @@ USE_TZ = True
STATIC_URL = '/static/'
PROJECT_DIR=os.path.dirname(__file__)
# TODO: STATIC_ROOT must be eventually edited
STATIC_ROOT = os.path.join(PROJECT_DIR,'static/')
CKEDITOR_UPLOAD_PATH = "uploads/"
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
......
select.admin-autocomplete {
width: 20em;
}
.select2-container--admin-autocomplete.select2-container {
min-height: 30px;
}
.select2-container--admin-autocomplete .select2-selection--single,
.select2-container--admin-autocomplete .select2-selection--multiple {
min-height: 30px;
padding: 0;
}
.select2-container--admin-autocomplete.select2-container--focus .select2-selection,
.select2-container--admin-autocomplete.select2-container--open .select2-selection {
border-color: #999;
min-height: 30px;
}
.select2-container--admin-autocomplete.select2-container--focus .select2-selection.select2-selection--single,
.select2-container--admin-autocomplete.select2-container--open .select2-selection.select2-selection--single {
padding: 0;
}
.select2-container--admin-autocomplete.select2-container--focus .select2-selection.select2-selection--multiple,
.select2-container--admin-autocomplete.select2-container--open .select2-selection.select2-selection--multiple {
padding: 0;
}
.select2-container--admin-autocomplete .select2-selection--single {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
}
.select2-container--admin-autocomplete .select2-selection--single .select2-selection__rendered {
color: #444;
line-height: 30px;
}
.select2-container--admin-autocomplete .select2-selection--single .select2-selection__clear {
cursor: pointer;
float: right;
font-weight: bold;
}
.select2-container--admin-autocomplete .select2-selection--single .select2-selection__placeholder {
color: #999;
}
.select2-container--admin-autocomplete .select2-selection--single .select2-selection__arrow {
height: 26px;
position: absolute;
top: 1px;
right: 1px;
width: 20px;
}
.select2-container--admin-autocomplete .select2-selection--single .select2-selection__arrow b {
border-color: #888 transparent transparent transparent;
border-style: solid;
border-width: 5px 4px 0 4px;
height: 0;
left: 50%;
margin-left: -4px;
margin-top: -2px;
position: absolute;
top: 50%;
width: 0;
}
.select2-container--admin-autocomplete[dir="rtl"] .select2-selection--single .select2-selection__clear {
float: left;
}
.select2-container--admin-autocomplete[dir="rtl"] .select2-selection--single .select2-selection__arrow {
left: 1px;
right: auto;
}
.select2-container--admin-autocomplete.select2-container--disabled .select2-selection--single {
background-color: #eee;
cursor: default;
}
.select2-container--admin-autocomplete.select2-container--disabled .select2-selection--single .select2-selection__clear {
display: none;
}
.select2-container--admin-autocomplete.select2-container--open .select2-selection--single .select2-selection__arrow b {
border-color: transparent transparent #888 transparent;
border-width: 0 4px 5px 4px;
}
.select2-container--admin-autocomplete .select2-selection--multiple {
background-color: white;
border: 1px solid #ccc;
border-radius: 4px;
cursor: text;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__rendered {
box-sizing: border-box;
list-style: none;
margin: 0;
padding: 0 5px;
width: 100%;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__rendered li {
list-style: none;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__placeholder {
color: #999;
margin-top: 5px;
float: left;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__clear {
cursor: pointer;
float: right;
font-weight: bold;
margin: 5px;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__choice {
background-color: #e4e4e4;
border: 1px solid #ccc;
border-radius: 4px;
cursor: default;
float: left;
margin-right: 5px;
margin-top: 5px;
padding: 0 5px;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__choice__remove {
color: #999;
cursor: pointer;
display: inline-block;
font-weight: bold;
margin-right: 2px;
}
.select2-container--admin-autocomplete .select2-selection--multiple .select2-selection__choice__remove:hover {
color: #333;
}
.select2-container--admin-autocomplete[dir="rtl"] .select2-selection--multiple .select2-selection__choice, .select2-container--admin-autocomplete[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder, .select2-container--admin-autocomplete[dir="rtl"] .select2-selection--multiple .select2-search--inline {
float: right;
}
.select2-container--admin-autocomplete[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
margin-left: 5px;
margin-right: auto;
}
.select2-container--admin-autocomplete[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
margin-left: 2px;
margin-right: auto;
}
.select2-container--admin-autocomplete.select2-container--focus .select2-selection--multiple {
border: solid #999 1px;
outline: 0;
}
.select2-container--admin-autocomplete.select2-container--disabled .select2-selection--multiple {
background-color: #eee;
cursor: default;
}