Commit efa9a2f0 authored by nikkastra's avatar nikkastra

now fixing the profile

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