New Feature: added image field in WidgetUser model and image tag in...

New Feature: added image field in WidgetUser model and image tag in details.html so each user has profile picture.

Improvement: edited settings.py and urls.py of widget_django_unchained folder to allow image posting.
parent f17d08e1
# Generated by Django 3.2.12 on 2022-05-17 16:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0023_remove_widgetuser_user_face'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='profile_pic',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-17 16:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0024_widgetuser_profile_pic'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile_pic',
field=models.ImageField(blank=True, default='faceless.png', null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-17 17:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0025_alter_widgetuser_profile_pic'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile_pic',
field=models.ImageField(blank=True, default='static/homepage/images/faceless.png', null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-17 18:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0026_alter_widgetuser_profile_pic'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile_pic',
field=models.ImageField(blank=True, default='faceless_9ltCukV.png', null=True, upload_to=''),
),
]
......@@ -8,6 +8,7 @@ class WidgetUser(models.Model):
last_name = models.CharField(max_length=50, default='last_name')
id_num = models.CharField(max_length=7, default='1234567')
email = models.CharField(max_length=50, default='someemail@gmail.com')
profile_pic = models.ImageField(default="faceless_9ltCukV.png", null=True, blank=True)
def __str__(self):
return self.last_name
......
......@@ -12,4 +12,9 @@
<li>{{ Department.dept_name }}</li>
<li>{{ Department.home_unit }}</li>
</ul>
<br>
<img src="{{ Department.widgetuser.profile_pic.url }}" width="20%">
{% endblock %}
\ No newline at end of file
......@@ -5,6 +5,6 @@ from . import views
app_name = "homepage"
urlpatterns = [
path('', views.index, name='index'),
path("users/<int:widgetuser_id>/details/", views.detail, name='details')
path("users/<int:widgetuser_id>/details/", views.detail, name='details'),
]
\ No newline at end of file
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
import environ
......@@ -125,6 +125,13 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/images/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
MEDIA_ROOT = os.path.join(BASE_DIR, 'homepage/static/homepage/images')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
......@@ -15,7 +15,8 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('announcements/', include('announcements.urls')),
......@@ -23,4 +24,4 @@ urlpatterns = [
path('forum/', include('forum.urls')),
path('assignments/', include('assignments.urls')),
path('admin/', admin.site.urls),
]
\ No newline at end of file
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ 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