Commit 166317a1 authored by Jose Luis Bautista's avatar Jose Luis Bautista

Added Profile functionality

parent 30743c91
from django import forms from django import forms
from django.forms import ModelForm from django.forms import ModelForm
from .models import key_model from .models import key_model, profile_model
class home(forms.Form): class home(forms.Form):
name = forms.CharField(label='Name: ', max_length = 25) name = forms.CharField(label='Name: ', max_length = 25)
class profile(forms.Form): class profileFormName(forms.ModelForm):
name = forms.CharField(label='', max_length = 25) class Meta:
model = profile_model
fields = ['profileName']
class profileFormBio(forms.ModelForm):
class Meta:
model = profile_model
fields = ['profileBio']
class profileFormImage(forms.ModelForm):
class Meta:
model = profile_model
fields = ['profileImage']
class key(forms.ModelForm): class key(forms.ModelForm):
class Meta: class Meta:
......
# Generated by Django 3.1.8 on 2021-04-07 05:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='profile_model',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('profileName', models.CharField(max_length=25)),
('profileBio', models.CharField(max_length=25)),
('profileImage', models.ImageField(upload_to='')),
],
),
]
# Generated by Django 3.1.8 on 2021-04-07 06:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0002_profile_model'),
]
operations = [
migrations.AlterField(
model_name='profile_model',
name='profileImage',
field=models.ImageField(null=True, upload_to=''),
),
]
# Generated by Django 3.1.8 on 2021-04-07 07:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0003_auto_20210407_1440'),
]
operations = [
migrations.AlterField(
model_name='profile_model',
name='profileImage',
field=models.ImageField(null=True, upload_to='images/'),
),
]
...@@ -4,3 +4,8 @@ from django.db import models ...@@ -4,3 +4,8 @@ from django.db import models
class key_model(models.Model): class key_model(models.Model):
keyName = models.CharField(max_length = 25) keyName = models.CharField(max_length = 25)
keyDesc = models.CharField(max_length = 25) keyDesc = models.CharField(max_length = 25)
class profile_model(models.Model):
profileName = models.CharField(max_length = 25)
profileBio = models.CharField(max_length = 25)
profileImage = models.ImageField(upload_to ='images/', null = True)
\ No newline at end of file
...@@ -15,17 +15,23 @@ Including another URLconf ...@@ -15,17 +15,23 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from .views import page_home, page_profile, page_key, page_today, page_this_week, page_today, KeyListView, new_key #from .views import page_home, page_profile, page_key, page_today, page_this_week, page_today, KeyListView, new_key, ProfileDetailView, ProfileNameView, ProfileBioView
from .views import *
urlpatterns = [ urlpatterns = [
#path('admin/', admin.site.urls), #path('admin/', admin.site.urls),
path('', page_home, name = 'home'), path('', page_home, name = 'home'),
path('home/', page_home, name = 'home'), path('home/', page_home, name = 'home'),
path('profile/', page_profile, name = 'profile'), path('profile/', ProfileDetailView.as_view(), name = 'profile'),
path('key/', KeyListView.as_view(), name = 'key'), path('key/', KeyListView.as_view(), name = 'key'),
path('this_week/', page_this_week, name = 'this_week'), path('this_week/', page_this_week, name = 'this_week'),
path('today/', page_today, name = 'today'), path('today/', page_today, name = 'today'),
path('new_key/', new_key, name = 'new_key'), path('new_key/', new_key, name = 'new_key'),
path('new_name/',ProfileNameView.as_view(), name = 'new_name'),
path('new_bio/',ProfileBioView.as_view(), name = 'new_bio'),
path('new_image/',ProfileImageView.as_view(), name = 'new_image'),
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.shortcuts import render, reverse, redirect from django.shortcuts import render, reverse, redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic import View, ListView from django.views.generic import View, ListView, DetailView, UpdateView
from datetime import datetime from datetime import datetime
from .forms import home, profile, key, this_week, today from .forms import home, key, this_week, today,profileFormName, profileFormBio, profileFormImage
from .models import key_model from .models import key_model, profile_model
name = None name = None
form = None form = None
def page_home(request): def page_home(request):
global name global name
global form
if name == None: if name == None:
if request.method == 'POST': if request.method == 'POST':
...@@ -22,7 +21,7 @@ def page_home(request): ...@@ -22,7 +21,7 @@ def page_home(request):
form = home() form = home()
return render(request, 'home.html', {'form' : form}) return render(request, 'home.html', {'form' : form})
else: else:
return render(request, 'home.html', {'form' : form, 'name' : name}) return render(request, 'home.html', {'name' : name})
def page_profile(request): def page_profile(request):
return render(request, 'profile.html') return render(request, 'profile.html')
...@@ -40,7 +39,7 @@ def new_key(request): ...@@ -40,7 +39,7 @@ def new_key(request):
if form.is_valid(): if form.is_valid():
form.save() form.save()
return redirect('key') return redirect('key')
return render(request,'new_key.html', {'form' : form}) return render(request,'update.html', {'form' : form})
def page_today(request): def page_today(request):
...@@ -52,3 +51,45 @@ def page_today(request): ...@@ -52,3 +51,45 @@ def page_today(request):
class KeyListView(ListView): class KeyListView(ListView):
model = key_model model = key_model
template_name = 'key.html' template_name = 'key.html'
class ProfileDetailView(DetailView):
model = profile_model
template_name = 'profile.html'
def get_object(self):
return profile_model.objects.first()
class ProfileNameView(UpdateView):
model = profile_model
template_name = 'update.html'
form_class = profileFormName
def get_object(self):
return profile_model.objects.first()
def get_success_url(self):
return reverse('profile')
class ProfileBioView(UpdateView):
model = profile_model
template_name = 'update.html'
form_class = profileFormBio
def get_object(self):
return profile_model.objects.first()
def get_success_url(self):
return reverse('profile')
class ProfileImageView(UpdateView):
model = profile_model
template_name = 'update.html'
form_class = profileFormImage
def get_object(self):
return profile_model.objects.first()
def get_success_url(self):
return reverse('profile')
...@@ -124,4 +124,8 @@ USE_TZ = True ...@@ -124,4 +124,8 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.1/howto/static-files/ # https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'BauJo/static')] STATICFILES_DIRS = [os.path.join(BASE_DIR, 'BauJo/static')]
\ No newline at end of file
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
</ul> </ul>
<button align = "center" href = "{% url 'new_key' %}">Add New Key</button> <a href = "{% url 'new_key' %}"><button>Add New Key</button></a>
{% endblock %} {% endblock %}
\ No newline at end of file
<h1> Type here new key: </h1>
<form action = '' method = "POST">
{% csrf_token %}
{{ form }}
<input type="submit" name="submit" id = "submit" value = "Click to add">
</form>
\ No newline at end of file
...@@ -8,9 +8,16 @@ ...@@ -8,9 +8,16 @@
{% block body %} {% block body %}
<br> <br>
<img src="{% static 'john.jpg' %}" width="600" height="400"> <img src= {{ object.profileImage.url}} width="400" height="400">
<h3> This is John Batungbacal. <br>He works at the SM department store as a sales representative. <br>He likes to play Mobile Legends and customizing his motorcycle.</h3> <br>
<a href = "{% url 'new_image' %}"><button>Edit Pic</button></a>
<h3>Name: {{object.profileName}}</h3>
<a href = "{% url 'new_name' %}"><button>Edit Name</button></a>
<br>
<h3>Bio: {{object.profileBio}}</h3>
<a href = "{% url 'new_bio' %}"><button>Edit Bio</button></a>
{% endblock %} {% endblock %}
\ No newline at end of file
<form action = '' method = "POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input type="submit" name="submit" id = "submit" value = "Add">
</form>
\ 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