Commit 874518a1 authored by Silje Odland's avatar Silje Odland
Browse files

adds custom user and dynamic url for profile page

parent ecaa62f1
{% extends 'base.html' %}
{% load static %}
{% block body %}
<div style="padding-top: 150px">
<p style="font-size:150%; position: absolute; margin-left:40%; margin-top:-1%">
Navn
</p>
<div style="padding-top: 50px">
<div style="border-radius: 20px ;margin-top: 50px;width: 60%; margin-left: 20%; background-color: white; height: 420px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
<p style="font-size:150%; position: absolute; margin-left:15%; padding-top: 50px">
{{knitter.first_name}} {{ knitter.last_name }}
</p>
<img src="{% static 'img/profilepic.png' %}" style="width: 10%; margin-left: 25%; margin-top: -5%">
<img src="{% static 'img/profilepic.png' %}" style="width: 10%; margin-left: 10%; padding-top: 35px">
<form>
<div class="form-group" style="margin-left:25%; margin-top:3%">
<p>Litt om meg:</p>
<textarea id="aboutme" rows="3" cols="80" ></textarea>
<div class="form-group" style="margin-left:10%; margin-top:50px">
<p><i>Litt om meg:</i></p>
<p> {{ knitter.about }} </p>
</div>
</form>
</div>
</div>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
# Generated by Django 3.0.3 on 2020-02-21 16:32
# Generated by Django 3.0.3 on 2020-02-23 19:51
from django.db import migrations, models
......
# Generated by Django 3.0.3 on 2020-02-23 19:51
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('feed', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='post',
name='publisher',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
from django.db import models
from ..users.models import Knitter
# Create your models here.
......@@ -7,4 +8,5 @@ from django.db import models
class Post(models.Model):
text = models.TextField(null=True, blank=True,max_length=4000)
image = models.ImageField(null=False)
publisher = models.ForeignKey(Knitter, null=True, on_delete=models.CASCADE)
from django.shortcuts import render
from ..feed.models import Post
from ..users.models import Knitter
# Create your views here.
def index(request):
......@@ -9,5 +10,6 @@ def startpage(request):
posts = Post.objects.all()
return render(request, "startpage.html", {'posts':posts})
def myprofile(request):
return render(request, "myprofile.html")
\ No newline at end of file
def myprofile(request,pk):
knitter = Knitter.objects.filter(pk=pk).first()
return render(request, "myprofile.html",{'knitter':knitter})
\ No newline at end of file
from django.contrib import admin
from .models import Knitter
# Register your models here.
admin.site.register(Knitter)
\ No newline at end of file
# Generated by Django 3.0.3 on 2020-02-23 19:51
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0011_update_proxy_permissions'),
]
operations = [
migrations.CreateModel(
name='Knitter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('about', models.CharField(blank=True, max_length=300, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
# Generated by Django 3.0.3 on 2020-02-23 20:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='knitter',
name='profilepicture',
field=models.ImageField(null=True, upload_to=''),
),
]
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class Knitter(AbstractUser):
about = models.CharField(max_length=300, null=True, blank=True)
profilepicture = models.ImageField(null= True)
......@@ -129,4 +129,5 @@ STATICFILES_DIRS = [
MEDIA_ROOT = 'uploads/'
MEDIA_URL = '/uploads/'
AUTH_USER_MODEL = 'users.Knitter'
......@@ -26,5 +26,5 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('', index),
path('startpage/', startpage),
path('myprofile/', myprofile),
path('myprofile/<int:pk>/', myprofile),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Supports Markdown
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