Skip to content
Snippets Groups Projects
Commit a27daa3b authored by Eck Balázs István's avatar Eck Balázs István
Browse files

Merge branch 'revert-9f29ae9d' into 'main'

Revert "asd"

See merge request !3
parents f81733a6 235f0426
No related branches found
No related tags found
1 merge request!3Revert "asd"
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
class Picture(models.Model): class Post(models.Model):
title = models.CharField(max_length=75) title = models.CharField(max_length=75)
body = models.TextField() body = models.TextField()
slug = models.SlugField() slug = models.SlugField()
......
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block title %} {% block title %}
New Picture New Post
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<section> <section>
<h1>New Picture</h1> <h1>New Post</h1>
<form class="form-with-validation" action="{% url 'posts:new-picture' %}" method="post" enctype="multipart/form-data"> <form class="form-with-validation" action="{% url 'posts:new-post' %}" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<button class="form-submit">Add Picture</button> <button class="form-submit">Add Post</button>
</form> </form>
</section> </section>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block title %} {% block title %}
{{ picture.title }} {{ post.title }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<section> <section>
<img <img
class="banner" class="banner"
src="{{ picture.banner.url }}" src="{{ post.banner.url }}"
alt="{{ picture.title }}" alt="{{ post.title }}"
/> />
<h1> <h1>
{{ picture.title }} {{ post.title }}
</h1> </h1>
<p>{{ picture.date }}</p> <p>{{ post.date }}</p>
<p>{{ picture.body }}</p> <p>{{ post.body }}</p>
</section> </section>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block title %} {% block title %}
Pictures Posts
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<section> <section>
<h1>Pictures</h1> <h1>Posts</h1>
{% for picture in pictures %} {% for post in posts %}
<article class="post"> <article class="post">
<h2> <h2>
<a href="{% url 'pictures:page' slug=picture.slug %}"> <a href="{% url 'posts:page' slug=post.slug %}">
{{ picture.title }} {{ post.title }}
</a> </a>
</h2> </h2>
<p>{{ picture.date }} by {{ picture.author }}</p> <p>{{ post.date }} by {{ post.author }}</p>
<p>{{ picture.body }}</p> <p>{{ post.body }}</p>
</article> </article>
{% endfor %} {% endfor %}
</section> </section>
......
File moved
...@@ -2,10 +2,10 @@ from django.contrib import admin ...@@ -2,10 +2,10 @@ from django.contrib import admin
from django.urls import path from django.urls import path
from . import views from . import views
app_name = "pictures" app_name = "posts"
urlpatterns = [ urlpatterns = [
path("", views.pictures_list, name="list"), path("", views.posts_list, name="list"),
path('new-picture/', views.picture_new, name="new-picture"), path('new-post/', views.post_new, name="new-post"),
path("<slug:slug>", views.picture_page, name="page") path("<slug:slug>", views.post_page, name="page")
] ]
\ No newline at end of file
...@@ -5,24 +5,24 @@ from . import forms ...@@ -5,24 +5,24 @@ from . import forms
def pictures_list(request): def posts_list(request):
pictures = Post.objects.all().order_by('-date') posts = Post.objects.all().order_by('-date')
return render(request, 'posts/posts_list.html', {'pictures': pictures}) return render(request, 'posts/posts_list.html', {'posts': posts})
def picture_page(request, slug): def post_page(request, slug):
picture = Post.objects.get(slug=slug) post = Post.objects.get(slug=slug)
return render(request, 'pictures/picture_page.html', {'picture': picture}) return render(request, 'posts/post_page.html', {'post': post})
@login_required(login_url="/users/login/") @login_required(login_url="/users/login/")
def picture_new(request): def post_new(request):
if request.method == 'POST': if request.method == 'POST':
form = forms.CreatePost(request.POST, request.FILES) form = forms.CreatePost(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
newpicture = form.save(commit=False) newpost = form.save(commit=False)
newpicture.author = request.user newpost.author = request.user
newpicture.save() newpost.save()
return redirect('pictures:list') return redirect('posts:list')
else: else:
form = forms.CreatePost() form = forms.CreatePost()
return render(request, 'pictures/picture_new.html', { 'form': form }) return render(request, 'posts/post_new.html', { 'form': form })
\ No newline at end of file \ No newline at end of file
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
<span role="img" aria-label="About" title="About">😀</span> <span role="img" aria-label="About" title="About">😀</span>
</a> | </a> |
{% if user.is_authenticated %} {% if user.is_authenticated %}
<a href="{% url 'pictures:list' %}"> <a href="{% url 'posts:list' %}">
<span role="img" aria-label="pictures" title="pictures">📰</span> <span role="img" aria-label="Posts" title="Posts">📰</span>
</a> | </a> |
<a href="{% url 'pictures:new-picture' %}"> <a href="{% url 'posts:new-post' %}">
<span role="img" aria-label="New picture" title="New picture">🆕</span> <span role="img" aria-label="New Post" title="New Post">🆕</span>
</a> | </a> |
<form class="logout" action="{% url 'users:logout' %}" method="post"> <form class="logout" action="{% url 'users:logout' %}" method="post">
{% csrf_token %} {% csrf_token %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment