Commit fd98d12d authored by Tang, Alexander's avatar Tang, Alexander
Browse files

Merge remote-tracking branch 'remotes/origin/master' into Alex_2020_06_12

# Conflicts:
#	.gitignore
#	blog/models.py
#	blog/static/blog/all_blogs.js
#	blog/templates/blog/all_blogs.html
#	blog/urls.py
#	blog/views.py
#	djangoblog.sqlite3
parents 44d44934 8e62d75a
/venv/ /venv/
.idea /.idea/
/djangoblog.sqlite3
/media/uploads/2020/
# Default ignored files
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="db" uuid="e51bebfe-b0d0-4eab-ba8d-948e5aa50875">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db.sqlite3</jdbc-url>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/sqlite-jdbc-3.25.1.jar</url>
</library>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/license.txt</url>
</library>
</libraries>
</data-source>
<data-source source="LOCAL" name="djangoblog" uuid="c07cad5e-d117-4345-a798-ec2d942518c0">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/djangoblog.sqlite3</jdbc-url>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/sqlite-jdbc-3.25.1.jar</url>
</library>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/license.txt</url>
</library>
</libraries>
</data-source>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="FacetManager">
<facet type="django" name="Django">
<configuration>
<option name="rootFolder" value="$MODULE_DIR$" />
<option name="settingsModule" value="blog/settings.py" />
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
<option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" />
<option name="trackFilePattern" value="migrations" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.6 (django_blog)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Django" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/article/templates" />
</list>
</option>
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (django_blog)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/django_blog.iml" filepath="$PROJECT_DIR$/.idea/django_blog.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -73,8 +73,8 @@ from .models import Blog ...@@ -73,8 +73,8 @@ from .models import Blog
def home(request): def home(request):
blogObjects = Blog.objects().all # grabs all objects from the DB table 'Blog' blogObjects = Blog.objects().all # grabs all objects from the DB table 'Blog'
return render(request, '<Website e.g. <App folder>/home.html', {'blogobjects':blogobjects}) 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** **2. home.html**
``` ```
...@@ -83,3 +83,49 @@ def home(request): ...@@ -83,3 +83,49 @@ def home(request):
{% endfor %} {% 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
...@@ -2,5 +2,7 @@ from django.contrib import admin ...@@ -2,5 +2,7 @@ from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Blog # importing Blog class from .models import Blog # importing Blog class
from .models import Comment
admin.site.register(Blog) admin.site.register(Blog)
\ No newline at end of file admin.site.register(Comment)
\ No newline at end of file
from django.forms import ModelForm, Textarea, HiddenInput
from blog.models import Comment
class CommentForm(ModelForm):
"""Form to save comments for a blog entry"""
class Meta:
model = Comment
# which fields should be edited?
fields = ['author', 'text', 'related_blog']
# labels for the fields
labels = {'author': 'Name'}
# how should the fields be shown?
widgets = {
'author': Textarea(attrs={'rows': 1}),
'text': Textarea(attrs={'rows': 5}),
'related_blog': HiddenInput()
}
# 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 from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
...@@ -15,16 +19,25 @@ class Migration(migrations.Migration): ...@@ -15,16 +19,25 @@ class Migration(migrations.Migration):
name='Blog', name='Blog',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('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( migrations.CreateModel(
name='Project', name='Comment',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)), ('author', models.TextField(max_length=150)),
('description', models.TextField()), ('text', models.TextField(max_length=1000)),
('date', models.DateField()), ('date', models.DateTimeField(default=datetime.datetime.now)),
('image', models.ImageField(upload_to='portfolio/images/')), ('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),
),
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment