Commit 8571a8b1 authored by Jersey Dayao's avatar Jersey Dayao 🏀

feat: added form field for image upload

parent ed8e79cc
......@@ -4,4 +4,4 @@ from .models import Post
class PostForm(ModelForm):
class Meta:
model = Post
fields = ["post_title", "post_body", "author"]
\ No newline at end of file
fields = ["post_title", "post_body", "author", "image"]
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-05-26 23:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_alter_post_pub_date'),
]
operations = [
migrations.AddField(
model_name='post',
name='image',
field=models.ImageField(blank=True, null=True, upload_to='images/'),
),
]
from django.db import models
from django.forms import ImageField
from homepage.models import WidgetUser
# Create your models here.
......@@ -11,6 +12,9 @@ class Post(models.Model):
on_delete=models.CASCADE,
default=None,
null=True)
image = models.ImageField(upload_to="images/",
blank=True,
null=True)
def __str__(self):
return self.post_title
......
......@@ -6,7 +6,7 @@
<h2 id="createHeader">New Forum Post</h2>
<form method="POST" action="">
<form method="POST" enctype="multipart/form-data" action="">
{% csrf_token %}
{{ post_form.as_p }}
<br/>
......
......@@ -9,15 +9,10 @@
<h3>{{ post.post_body }}</h3>
<div>
{% if post.id == 1 %}
<img src = "{% static 'forum/images/pepeWOW.jpeg' %}" alt = ":o">
{% elif post.id == 2 %}
<img src = "{% static 'forum/images/pepeBLUSH.jpeg' %}" alt = "hehe>">
{% else %}
<img src = "{% static 'forum/images/pepeTIRED.jpeg' %}" alt = "profile image">
{% if post.image %}
<img src="{{ post.image.url }}" alt="x_x bad server x_x">
{% endif %}
</div>
</div>
<br/>
<br/>
......
Markdown is supported
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