Commit 6fa0b8c1 authored by Charles Lim's avatar Charles Lim

Fixed image uploading and rendering for homepage.

parent 338f3476
# Generated by Django 4.0.4 on 2022-05-23 04:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_widgetuser_profile_pic'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile_pic',
field=models.FileField(blank=True, null=True, upload_to='media/homepage'),
),
]
# Generated by Django 4.0.4 on 2022-05-23 04:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0007_alter_widgetuser_profile_pic'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile_pic',
field=models.ImageField(blank=True, null=True, upload_to='media/homepage'),
),
]
from django.db import models from django.db import models
# Model for Department
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length=100) dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100) home_unit = models.CharField(max_length=100)
...@@ -9,8 +8,6 @@ class Department(models.Model): ...@@ -9,8 +8,6 @@ class Department(models.Model):
def __str__(self): def __str__(self):
return self.dept_name + ", " + self.home_unit return self.dept_name + ", " + self.home_unit
# Model for Widget User
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=100) first_name = models.CharField(max_length=100)
...@@ -19,8 +16,8 @@ class WidgetUser(models.Model): ...@@ -19,8 +16,8 @@ class WidgetUser(models.Model):
id_num = models.CharField(max_length=7, default="123456") id_num = models.CharField(max_length=7, default="123456")
email = models.EmailField( email = models.EmailField(
max_length=256, default="john.appleseed@gmail.com") max_length=256, default="john.appleseed@gmail.com")
profile_pic = models.FileField( profile_pic = models.ImageField(
upload_to="uploads", null=True, blank=True) upload_to="media/homepage", null=True, blank=True)
department = models.ForeignKey( department = models.ForeignKey(
Department, Department,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
......
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
{% endblock %} {% endblock %}
{% block header %} {% block header %}
{% if object.profile_pic != None and object.profile_pic != '' %}
<img width=60 height=60 src="{% get_media_prefix %}{{object.profile_pic}}"/>
{% else %}
<img width=60 height=60 src="{% static 'homepage/default_profilepic.png' %}"/> <img width=60 height=60 src="{% static 'homepage/default_profilepic.png' %}"/>
{% endif %}
{{object.last_name}}, {{object.first_name}} {{object.middle_name}} {{object.last_name}}, {{object.first_name}} {{object.middle_name}}
{% endblock %} {% endblock %}
......
...@@ -16,6 +16,6 @@ ...@@ -16,6 +16,6 @@
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Submit"> <input type="submit" value="Save New User">
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
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