Commit 7ecf0a1c authored by nikkastra's avatar nikkastra

better profile code

profile picture only, images not rendering
parent efa9a2f0
from django.contrib import admin
# Register your models here.
from .models import *
class NameAdmin(admin.ModelAdmin):
model = Name
class TasksAdmin(admin.ModelAdmin):
model = Tasks
admin.site.register(Name, NameAdmin)
admin.site.register(Tasks, TasksAdmin)
\ No newline at end of file
......@@ -2,10 +2,16 @@ from django import forms
from .models import *
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)
class NicknameAndBio(forms.ModelForm):
class Meta:
model=Name
fields=['nickname', 'bio']
\ No newline at end of file
model = Name
fields = ['nickname', 'bio']
class Picture(forms.ModelForm):
class Meta:
model = Name
fields = ['image']
\ No newline at end of file
# Generated by Django 3.1.7 on 2021-04-07 22:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bulletjournal', '0002_auto_20210408_0054'),
]
operations = [
migrations.AddField(
model_name='name',
name='image',
field=models.ImageField(default='static/img/default.jpg', upload_to='profilepictures'),
),
migrations.AlterField(
model_name='name',
name='bio',
field=models.CharField(default='A short bio about yourself', max_length=200),
),
migrations.AlterField(
model_name='name',
name='nickname',
field=models.CharField(default='Your nickname', max_length=50),
),
]
......@@ -2,15 +2,16 @@ from django.db import models
class Name(models.Model):
name = models.CharField(max_length=100, unique=True)
name = models.CharField(max_length=100, unique=True, default="test")
nickname = models.CharField(max_length=50, default='Your nickname')
bio = models.CharField(max_length=200, default='A short bio about yourself')
image = models.ImageField(upload_to='profilepictures', default='static/img/default.jpg')
def __str__(self):
return '{} {} {}'.format(self.name, self.nickname, self.bio)
def get_absolute_url(self):
return reverse('name_detail', args=[str(self.name)])
return reverse('name_detail', args=[str(self.pk)])
@property
def is_tutorial(self):
......
......@@ -10,6 +10,6 @@ urlpatterns = [
path('key', key, name = 'key'),
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_detail')
path('names', NameListView.as_view(), name = 'name_list'),
path('name/<int:pk>', NameDetailView.as_view(), name = 'name_detail')
]
\ No newline at end of file
......@@ -44,16 +44,25 @@ def home(request):
def profile(request):
if request.method == 'POST':
form = NicknameAndBio(request.POST)
global name_dict
info = Name.objects.get(name=name_dict['name'])
picture = info.image
nickname = info.nickname
bio = info.bio
if request.method == "POST":
form = Picture(request.POST, request.FILES)
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)
form.save()
test = Name.objects.get(name="test")
info.image = test.image
picture = info.image
info.save()
test.delete()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form':form}
return render(request, 'profile.html', info_dict)
else:
form = NicknameAndBio()
form = Picture()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form':form}
return render(request, 'profile.html', info_dict)
......
......@@ -124,5 +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/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'mysite/media/')
{% extends 'base.html' %}
{% block title %}{{ object.name }}{% endblock %}
{% block title %}{{ Name.name }}{% endblock %}
{% block content %}
<h1>{{ object.name }}</h1>
<h1>{{ Name.name }}</h1>
<p>kung ano man to</p>
{% endblock %}
\ No newline at end of file
......@@ -8,10 +8,15 @@
{% block content %}
<h1> Profile </h1>
<img src="{% static 'img/picturekoparasalahat.jpg' %}" />
<img src="{{picture}}" alt="hindi ako lilitaw" />
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type='submit'>Change</button>
</form>
<ul>
<li> Franz Leonard Atanacio </li>
<li> "pogi" </li>
<li> di raw masyadong masarap pero pwede na </li>
<li> {{name}} </li>
<li> {{nickname}} </li>
<li> {{bio}} </li>
</ul>
{% 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