Skip to content

Commit

Permalink
BE-thêm data, thêm đk trả tiền, hoàn tiền của rent, link FE phần xếp …
Browse files Browse the repository at this point in the history
…hạng, chỉnh giao diện admin
  • Loading branch information
TTTThanh2812 committed Jul 22, 2023
1 parent e79559c commit 4a835bc
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 245 deletions.
Binary file modified Rent_boardgame/Rent_boardgame/__pycache__/settings.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Rent_boardgame/Rent_boardgame/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'userauths',
'rent',
'myadmin.apps.MyAdminConfig',
# 'notifications',
'notifications',
]

MIDDLEWARE = [
Expand Down
Binary file modified Rent_boardgame/boardgame/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file modified Rent_boardgame/boardgame/__pycache__/models.cpython-310.pyc
Binary file not shown.
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: 2 additions & 0 deletions Rent_boardgame/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
path('account/', views.account, name='account'),
path('change_password/', views.change_password, name='change_password'),
path('edit_infomation/', views.edit_infomation, name='edit_infomation'),
path('leaderboard/', views.leaderboard, name='leaderboard'),
path('notification/', views.notification, name='notification'),
]
24 changes: 23 additions & 1 deletion Rent_boardgame/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib import messages
from django.contrib.auth import update_session_auth_hash
from django.urls import reverse
from notifications.models import Notification

from boardgame.models import Category, Boardgame, Version, Author, Producer
from userauths.models import User
Expand Down Expand Up @@ -105,4 +106,25 @@ def edit_infomation(request):
context = {
'form': form
}
return render(request, 'core/edit_infomation.html', context)
return render(request, 'core/edit_infomation.html', context)

def leaderboard(request):
top_boardgames = Boardgame.objects.annotate(avg_rating=models.Avg('reviews__rating')).order_by('-avg_rating')
for t_boardgame in top_boardgames:
most_recent_review = t_boardgame.reviews.order_by('-date').first()
t_boardgame.most_recent_comment = most_recent_review

return render(request, 'core/leaderboard.html', {
'top_boardgames': top_boardgames,
})

def notification(request):
# unread_notifications = Notification.objects.filter(recipient=request.user, read=False)

# unread_notifications.update(read=True)

context = {
# 'unread_notifications': unread_notifications,
}

return render(request, 'core/notification.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Rent_boardgame/myadmin/__pycache__/admin.cpython-310.pyc
Binary file not shown.
19 changes: 17 additions & 2 deletions Rent_boardgame/myadmin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,24 @@ class RentBoardgameItemInline(admin.TabularInline):
model = RentBoardgameItem
form = RentBoardgameItemForm
formset = RentBoardgameItemInlineFormSet
extra = 1
extra = 0
# fields = ['boardgame_number__boardgame', 'boardgame_number', 'quantity', 'rental_price', 'description']
fieldsets = [
('Boardgame Number Details', {
'fields': ['get_boardgame', 'boardgame_number', 'quantity', 'rental_price', 'description'], # Hiển thị trường boardgame_number, description và boardgame_number.boardgame
}),
# Thêm các trường khác của RentBoardgameItem tùy ý ở đây
]
readonly_fields = ['get_boardgame', 'boardgame_number', 'quantity', 'rental_price']

def get_boardgame(self, obj):
return obj.boardgame_number.boardgame if obj.boardgame_number else None
get_boardgame.short_description = 'Boardgame'

class RentBoardgameAdmin(admin.ModelAdmin):
inlines = [RentBoardgameItemInline]
list_display = ['renter', 'rid', 'start_date', 'end_date', 'order_status', 'rental_status', 'payment_status','deposit_refund_status', 'description']
list_filter = ['renter', 'order_status', 'rental_status']

def update_boardgame_numbers(self, obj):
# print('update_boardgame_numbers')
Expand Down Expand Up @@ -168,7 +182,8 @@ def save_related(self, request, form, formsets, change):


class UserAdmin(admin.ModelAdmin):
list_display = ['username', 'email']
list_display = ['user_id', 'username', 'phone_number', 'email']
list_filter = ['user_id', 'username']

# class GlobalSearchAdmin(admin.AdminSite):
# def get_search_results(self, request, queryset, search_term):
Expand Down
Binary file modified Rent_boardgame/rent/__pycache__/models.cpython-310.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.1 on 2023-07-22 01:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rent', '0002_initial'),
]

operations = [
migrations.AddField(
model_name='rentboardgame',
name='deposit_refund_status',
field=models.CharField(choices=[('not_refunded', 'Not Refunded'), ('refunded', 'Refunded')], default='not_refunded', max_length=20),
),
migrations.AddField(
model_name='rentboardgame',
name='payment_status',
field=models.CharField(choices=[('not_paid', 'Not Paid'), ('paid', 'Paid')], default='not_paid', max_length=20),
),
]
18 changes: 18 additions & 0 deletions Rent_boardgame/rent/migrations/0004_rentboardgame_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2023-07-22 01:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rent', '0003_rentboardgame_deposit_refund_status_and_more'),
]

operations = [
migrations.AddField(
model_name='rentboardgame',
name='description',
field=models.TextField(blank=True, default='This is notes on orders', null=True),
),
]
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions Rent_boardgame/rent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ class RentBoardgame(models.Model):

order_status = models.CharField(max_length=20, choices=ORDER_STATUS_CHOICES, default='pending')
rental_status = models.CharField(max_length=20, choices=RENTAL_STATUS_CHOICES, blank=True, null=True)
payment_status = models.CharField(
max_length=20,
choices=[('not_paid', 'Not Paid'), ('paid', 'Paid')],
default='not_paid',
)
deposit_refund_status = models.CharField(
max_length=20,
choices=[('not_refunded', 'Not Refunded'), ('refunded', 'Refunded')],
default='not_refunded',
)
description = models.TextField(null=True, blank=True, default="This is notes on orders")

def is_due_for_payment(self):
return self.end_date < timezone.now().date()

def is_deposit_refunded(self):
return self.deposit_refund_status == 'refunded'

def update_rental_status(self):
now = timezone.now().date()
Expand Down Expand Up @@ -123,6 +140,10 @@ def save(self, *args, **kwargs):
self.rid = 'rent01'
self.update_boardgame_numbers()
self.update_rental_status()
if self.is_due_for_payment() and self.payment_status != 'paid':
self.payment_status = 'not_paid'
if self.is_deposit_refunded() and self.deposit_refund_status != 'refunded':
self.deposit_refund_status = 'not_refunded'
super(RentBoardgame, self).save(*args, **kwargs)

self.rental_price = sum(item.rental_price for item in self.items.all())
Expand Down
4 changes: 2 additions & 2 deletions Rent_boardgame/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
<div class="ml-48 space-x-6 w-1/3">
<a href="/" class="text-lg font-semibold hover:text-teal-500">Trang chủ</a> <!-- click trả về trang chủ -->
<a href="{% url "core:allCategories" %}" class="text-lg font-semibold hover:text-teal-500">Thể loại</a> <!-- click đi tới thể loại -->
<a href="#" class="text-lg font-semibold hover:text-teal-500">Xếp hạng</a> <!-- click đi tới xếp hạng -->
<a href="{% url "core:leaderboard" %}" class="text-lg font-semibold hover:text-teal-500">Xếp hạng</a> <!-- click đi tới xếp hạng -->
</div>

<div class="space-x-6">
<button type="button"
class=" text-black-400 hover:text-gray-500 rounded-full focus:ring-offset-black-800">
<a href="#" class="fa fa-bell fa-lg"></a>
<a href="{% url "core:notification" %}" class="fa fa-bell fa-lg"></a>
</button>
<button type="button"
class=" text-black-400 hover:text-gray-500 rounded-full focus:ring-offset-black-800">
Expand Down
Loading

0 comments on commit 4a835bc

Please sign in to comment.