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