Skip to content

Commit

Permalink
Lấy thông tin người dùng(80%)
Browse files Browse the repository at this point in the history
Chưa lấy được họ tên, có thể hiển thị lên trang account
  • Loading branch information
TTTThanh2812 committed Jun 25, 2023
1 parent 38dc1c9 commit a7d6bfd
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 69 deletions.
Binary file modified Rent_boardgame/boardgame/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified Rent_boardgame/boardgame/__pycache__/views.cpython-310.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.1 on 2023-06-25 10:34

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('boardgame', '0002_boardgamereviews_remove_review_boardgame_and_more'),
]

operations = [
migrations.AlterField(
model_name='boardgamereviews',
name='user',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='user_reviews', to=settings.AUTH_USER_MODEL),
),
]
Binary file not shown.
2 changes: 1 addition & 1 deletion Rent_boardgame/boardgame/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def update_boardgame_stats_on_delete(sender, instance, **kwargs):
(5, "★★★★★"),
)
class BoardgameReviews(models.Model):
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name="user_reviews")
boardgame = models.ForeignKey(Boardgame, on_delete=models.SET_NULL, null=True, related_name="reviews")
review = models.TextField()
rating = models.IntegerField(choices=RATING, default=None)
Expand Down
Binary file modified Rent_boardgame/core/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified Rent_boardgame/core/__pycache__/views.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Rent_boardgame/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
# path('contact/', views.contact, name='contact'),
path('allCategories/', views.allCategories, name='allCategories'),
path('category/<cid>/', views.category_view, name='category'),

path("account/", views.account, name="account"),
]
12 changes: 9 additions & 3 deletions Rent_boardgame/core/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.shortcuts import render, redirect
from django.db import models
from django.contrib.auth import logout, login, authenticate
from django.contrib.auth.decorators import login_required

from django.contrib.auth.models import User
from boardgame.models import Category, Boardgame#, Rating, Review

from userauths.models import User

# from .models import UserProfile

Expand Down Expand Up @@ -63,4 +63,10 @@ def category_view(request, cid):
'boardgames': boardgames,
})


@login_required
def account(request):
user = User.objects.get(user_id=request.user.user_id)
context = {
'user': user
}
return render(request, 'core/account.html', context)
Binary file modified Rent_boardgame/db.sqlite3
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Rent_boardgame/templates/boardgame/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h4 class="text-xxl text-gray-500"> Customer reviews </h4>
<p class="text-xl text-gray-500"><strong>Tổng đánh giá: </strong>{{ reviews.count }}</p>
{% for r in page_obj %}
<div class="review">
<p class="text-xl text-gray-500"><strong>Người đánh giá: </strong>{{ r.user.username|title }}</p>
<p class="text-xl text-gray-500"><strong>Người đánh giá: </strong>{{ r.user_reviews.username|title }}</p>
<p class="text-xl text-gray-500"><strong>Thời gian đánh giá: </strong>{{ r.date| date:"d M, Y" }}</p>
<p class="text-xl text-gray-500"><strong>Đánh giá: </strong>{{ r.review }}</p>
<p class="text-xl text-gray-500"><strong>Số sao: </strong>{{ r.rating}}</p>
Expand Down
76 changes: 16 additions & 60 deletions Rent_boardgame/templates/core/account.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
<!DOCTYPE html>
<html lang="en">
{% extends 'core/base.html' %}
{% load static %}

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./test.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="./Tailwind/build/tailwind.css">
<link rel="stylesheet" href="./font.css">
</head>
{% block title %}All Category{% endblock %}

<body>
<div>
<div class="grid grid-cols-3 gap-4 justify-items-center items-center">
<div class="text-black font-semibold text-3xl pt-6 justify-self-start">
Logo
</div>
<div class="flex pt-6 gap-x-6">
<a href="#" class=" text-black hover:text-[#0FB3AFCC] rounded-md px-3 py-2 text-md font-medium"
aria-current="page">
Trang chủ
</a>
<a href="#" class=" text-black hover:text-[#0FB3AFCC] rounded-md px-3 py-2 text-md font-medium"
aria-current="page">
Thể loại
</a>
<a href="#" class=" text-black hover:text-[#0FB3AFCC] rounded-md px-3 py-2 text-md font-medium"
aria-current="page">
Xếp hạng
</a>
<a href="#" class=" text-[#0FB3AF] hover:text-[#0FB3AFCC] rounded-md px-3 py-2 text-md font-medium"
aria-current="page">
Tài khoản
</a>
</div>
<div class="pt-6 mx-6xl flex space-x-8 justify-self-end px-6">
<a href=""><button type="button"
class=" text-black-400 hover:text-gray-500 rounded-full focus:ring-offset-black-800">
<i class="fa fa-bell fa-lg"></i>
</button></a>
</div>
</div>
</div>
{% block content %}

<div class="grid grid-cols-2 justify-items-center px-56 pt-32">
<div class="relative max-w-xs overflow-hidden bg-cover bg-no-repeat pt-6 self-center" data-te-ripple-init
Expand All @@ -71,27 +27,27 @@
<tbody>
<tr>
<td class="text-[#0FB3AF]">MSKH:</td>
<td class="pl-8">12345678 </td>
<td class="pl-8">{{ user.user_id }}</td>
</tr>
<tr>
<td class="text-[#0FB3AF]">Họ và tên:</td>
<td class="pl-8">ABC</td>
<td class="pl-8">{{ user }} </td>
</tr>
<tr>
<td class="text-[#0FB3AF]">Số điện thoại:</td>
<td class="pl-8">0123456789</td>
<td class="pl-8">{{ user.phone_number }}</td>
</tr>
<tr>
<td class="text-[#0FB3AF]">Email:</td>
<td class="pl-8">abc@gmail.com</td>
<td class="pl-8">{{ user.email }}</td>
</tr>
<tr>
<td class="text-[#0FB3AF]">Điểm tích lũy:</td>
<td class="pl-8">400</td>
</tr>
<tr>
<td class="text-[#0FB3AF]">Địa chỉ:</td>
<td class="pl-8">123/45/678/9</td>
<td class="pl-8">{{ user.address }}</td>
</tr>
</tbody>
</table>
Expand All @@ -101,10 +57,12 @@
</a>
</div>
<div class="sm:flex sm:space-x-8 pt-6 font-medium">
<button type="button" class="bg-[#C32F2F] hover:bg-[#C32F2FCC] rounded-md px-3 text-sm h-8
text-white" style="font-family: Maven Pro;">
Đăng xuất
</button>
<a href={% url "userauths:sign_out" %}>
<button type="button" class="bg-[#C32F2F] hover:bg-[#C32F2FCC] rounded-md px-3 text-sm h-8
text-white" style="font-family: Maven Pro;">
Đăng xuất
</button>
</a>
<a href="">
<button type="button" class="bg-[#0FB3AF] hover:bg-[#0FB3AFCC] rounded-md px-3 text-sm h-8
text-white" style="font-family: Maven Pro;">
Expand Down Expand Up @@ -305,6 +263,4 @@
</div>
</div>
</div>
</body>

</html>
{% endblock %}
2 changes: 1 addition & 1 deletion Rent_boardgame/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<a href="#" class="fa fa-bell fa-lg"></a>
</button>
{% if request.user.is_authenticated %}
{% comment %} <a href="#" class="px-6 py-3 text-lg font-semibold bg-teal-500 text-white rounded-xl hover:bg-teal-700">Tài khoản</a> {% endcomment %}
<a href="{% url "core:account"%}" class="px-6 py-3 text-lg font-semibold bg-teal-500 text-white rounded-xl hover:bg-teal-700">Tài khoản</a>
<a href="{% url "userauths:sign_out" %}" class="px-6 py-3 text-lg font-semibold bg-red-500 text-white rounded-xl hover:bg-red-700">Đăng xuất</a>
{% else %}
<a href="{% url "userauths:sign_in" %}" class="px-6 py-3 text-lg font-semibold bg-teal-500 text-white rounded-xl hover:bg-teal-700">Đăng nhập</a>
Expand Down
Binary file modified Rent_boardgame/userauths/__pycache__/models.cpython-310.pyc
Binary file not shown.
7 changes: 5 additions & 2 deletions Rent_boardgame/userauths/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 4.2.1 on 2023-06-20 17:46
# Generated by Django 4.2.1 on 2023-06-25 10:34

import django.contrib.auth.models
from django.db import migrations, models
import django.utils.timezone
import shortuuid.django_fields


class Migration(migrations.Migration):
Expand All @@ -17,7 +18,6 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(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')),
Expand All @@ -28,6 +28,9 @@ class Migration(migrations.Migration):
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('email', models.EmailField(max_length=254, unique=True)),
('username', models.CharField(max_length=100)),
('user_id', shortuuid.django_fields.ShortUUIDField(alphabet='1234567890', length=6, max_length=100, prefix='user', primary_key=True, serialize=False, unique=True)),
('phone_number', models.CharField(blank=True, max_length=20)),
('address', models.CharField(blank=True, max_length=255)),
('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')),
],
Expand Down
Binary file not shown.
5 changes: 5 additions & 0 deletions Rent_boardgame/userauths/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from shortuuid.django_fields import ShortUUIDField


class User(AbstractUser):
email = models.EmailField(unique=True)
username = models.CharField(max_length=100)
user_id = ShortUUIDField(unique=True, primary_key=True, prefix="user", alphabet='1234567890', length=6, max_length=100)
phone_number = models.CharField(max_length=20, blank=True)
address = models.CharField(max_length=255, blank=True)

USERNAME_FIELD = "email"
REQUIRED_FIELDS = ['username']
Expand Down

0 comments on commit a7d6bfd

Please sign in to comment.