Commit efa9a2f0 authored by nikkastra's avatar nikkastra

now fixing the profile

parent 049de075
from django import forms from django import forms
from .models import *
class FirstName(forms.Form): class FirstName(forms.Form):
name = forms.CharField(label="Hello! What is your name? ", max_length=100) name=forms.CharField(label="Hello! What is your name? ", max_length=100)
\ No newline at end of file
class NicknameAndBio(forms.ModelForm):
class Meta:
model=Name
fields=['nickname', 'bio']
\ No newline at end of file
...@@ -3,8 +3,8 @@ from django.db import models ...@@ -3,8 +3,8 @@ from django.db import models
class Name(models.Model): class Name(models.Model):
name = models.CharField(max_length=100, unique=True) name = models.CharField(max_length=100, unique=True)
nickname = models.CharField(max_length=50) nickname = models.CharField(max_length=50, default='Your nickname')
bio = models.CharField(max_length=200, default='bobo ako') bio = models.CharField(max_length=200, default='A short bio about yourself')
def __str__(self): def __str__(self):
return '{} {} {}'.format(self.name, self.nickname, self.bio) return '{} {} {}'.format(self.name, self.nickname, self.bio)
......
...@@ -11,5 +11,5 @@ urlpatterns = [ ...@@ -11,5 +11,5 @@ urlpatterns = [
path('this_week', thisweek, name = 'thisweek'), path('this_week', thisweek, name = 'thisweek'),
path('today', today, name = 'today'), path('today', today, name = 'today'),
path('name', NameListView.as_view(), name = 'name_list'), path('name', NameListView.as_view(), name = 'name_list'),
path('name1/<int:pk>', NameDetailView.as_view(), name = 'name_list') path('name1/<int:pk>', NameDetailView.as_view(), name = 'name_detail')
] ]
\ No newline at end of file
...@@ -25,17 +25,17 @@ class HomePageView(View): ...@@ -25,17 +25,17 @@ class HomePageView(View):
return render(request, 'index.html', {'form': form}) return render(request, 'index.html', {'form': form})
def home(request): def home(request):
if len(name_dict)==1: if len(name_dict) == 1:
return render(request, 'index.html', name_dict) return render(request, 'index.html', name_dict)
elif request.method == 'POST': elif request.method == 'POST':
form = FirstName(request.POST) form=FirstName(request.POST)
if form.is_valid(): if form.is_valid():
name_dict['name'] = form.cleaned_data['name'] name_dict['name'] = form.cleaned_data['name']
try: try:
if Name.objects.get(name=name_dict['name']) in Name.objects.all(): if Name.objects.get(name=name_dict['name']) in Name.objects.all():
return render(request,'index.html', name_dict) return render(request,'index.html', name_dict)
except: except:
person_info = Name(name=name_dict['name'], nickname='no nickname', bio='no bio') person_info = Name(name=name_dict['name'])
person_info.save() person_info.save()
return render(request, 'index.html', name_dict) return render(request, 'index.html', name_dict)
else: else:
...@@ -44,7 +44,17 @@ def home(request): ...@@ -44,7 +44,17 @@ def home(request):
def profile(request): def profile(request):
return render(request, 'profile.html') if request.method == 'POST':
form = NicknameAndBio(request.POST)
if form.is_valid():
info = Name.objects.get(name=name_dict['name'])
info.nickname = form.cleaned_data['nickname']
info.bio = form.cleaned_data['bio']
new_info = info.save()
return redirect('name_detail', pk=new_info)
else:
form = NicknameAndBio()
return render(request, 'profile.html', info_dict)
def key(request): def key(request):
......
...@@ -124,3 +124,5 @@ USE_TZ = True ...@@ -124,3 +124,5 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'mysite/static'),] STATICFILES_DIRS = [os.path.join(BASE_DIR, 'mysite/static'),]
MEDIA_URL = '/profile pictures/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'mysite/profile pictures/')
{% extends 'base.html' %}
{% block title %}{{ object.name }}{% endblock %}
{% block content %}
<h1>{{ object.name }}</h1>
<p>kung ano man to</p>
{% endblock %}
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{% if object_list %} {% if object_list %}
{% for name in object_list %} {% for name in object_list %}
<li> <li>
<a href="{{name.get_absolute_url}}">{{name.name}}</a> <a href="{{Name.get_absolute_url}}">{{Name.name}}</a>
</li> </li>
{% endfor %} {% endfor %}
{% else %} {% else %}
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
{% if name %} {% if name %}
<p>Hello, {{name}}! Today is gonna be a great day!</p> <p>Hello, {{name}}! Today is gonna be a great day!</p>
{% else %} {% else %}
<form action="/home" method="post" id="nickname"> <form action="/home" method="post">
{% csrf_token %} {% csrf_token %}
{{form}} {{form}}
<input type="Submit" value="Submit"> <input type="Submit" value="Submit">
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
{% block content %} {% block content %}
<h1> Profile </h1> <h1> Profile </h1>
<img src="{% static 'img/picturekoparasalahat.jpg' %}" />
<ul> <ul>
<li> Franz Leonard Atanacio </li> <li> Franz Leonard Atanacio </li>
<li> "pogi" </li> <li> "pogi" </li>
<li> di raw masyadong masarap pero pwede na </li> <li> di raw masyadong masarap pero pwede na </li>
</ul> </ul>
<img src="{% static 'img/picturekoparasalahat.jpg' %}" />
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -16,8 +16,13 @@ Including another URLconf ...@@ -16,8 +16,13 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('', include('bulletjournal.urls')), path('', include('bulletjournal.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
urlpatterns += 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