Browse Source

в админке выводится имя пользователя, сделавшего заказ #19

adminpanel_changes
Fynjy 1 year ago
parent
commit
0e474650e5
  1. 2
      adminpanel/settings.py
  2. 21
      adminpanelapp/admin.py
  3. 24
      adminpanelapp/models.py

2
adminpanel/settings.py

@ -24,7 +24,7 @@ load_dotenv()
SECRET_KEY = os.getenv('PLATFORM_ADMINPANEL_SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True
ALLOWED_HOSTS = ['*']

21
adminpanelapp/admin.py

@ -2,7 +2,7 @@ from django.contrib.auth.models import User, Group
from django.http import HttpResponseRedirect
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.utils.safestring import mark_safe
from .models import Orders
from .models import Orders, Users
from django.contrib import admin, messages
from django.urls import reverse
@ -10,6 +10,18 @@ from django.urls import reverse
class OrdersAdmin(admin.ModelAdmin):
list_display = (
'orderName', 'orderCreateDateTime', 'orderDesc', 'orderAddress',
'catID', 'userName', 'orderStatus', 'show_photo', 'show_photopay',
)
actions = ['send_message']
exclude = ['orderAccess', 'userID', 'orderPhoto', 'orderPhotoPay']
def userName(self, obj):
user = Users.objects.get(user_id=obj.userID)
return user.userName
def changeform_view(self, request, object_id=None, form_url='', extra_context=None):
extra_context = extra_context or {}
@ -22,10 +34,6 @@ class OrdersAdmin(admin.ModelAdmin):
def has_add_permission(self, request):
return False
list_display = ('orderName', 'orderCreateDateTime', 'orderDesc', 'orderAddress', 'show_photo', 'show_photopay')
actions =['send_message']
exclude = ['orderAccess', 'userID', 'orderPhoto', 'orderPhotoPay']
def show_photo(self, obj):
html = obj.get_photo_html()
return mark_safe(html)
@ -73,6 +81,5 @@ admin.site.unregister(Group) # Снятие регистрации станда
admin.site.register(User, CustomUserAdmin) # Регистрация настроенного класса администратора пользователей
admin.site.register(Group, CustomGroupAdmin) # Регистрация настроенного класса администратора групп
admin.site.register(Orders, OrdersAdmin)
admin.site.register(Orders, OrdersAdmin)

24
adminpanelapp/models.py

@ -1,11 +1,26 @@
import time
from urllib.parse import quote
import requests
from django.db import models
from bot_sys.config import GetTelegramBotApiToken
class Users(models.Model):
user_id = models.CharField(max_length=100, primary_key=True)
userName = models.CharField(max_length=100, verbose_name='Имя пользователя')
userFirstName = models.CharField(max_length=100, verbose_name='Имя')
userLastName = models.CharField(max_length=100, verbose_name='Фамилия')
userIsBot = models.BooleanField(verbose_name='Является ботом')
userLanguageCode = models.CharField(max_length=100, verbose_name='Код языка')
userPhoto = models.ImageField(verbose_name='Фото пользователя')
userAccess = models.CharField(max_length=100, verbose_name='Доступ')
createDateTime = models.DateTimeField(auto_now_add=True, verbose_name='Дата и время создания')
class Meta:
verbose_name_plural = 'Заказы'
managed = False
db_table = 'users'
class Orders(models.Model):
orderID = models.AutoField(primary_key=True, verbose_name='id заказа')
userID = models.CharField(max_length=100, verbose_name='id пользователя в tg', null=True)
@ -17,6 +32,7 @@ class Orders(models.Model):
orderAccess = models.CharField(max_length=100, verbose_name='доступ', blank=True, null=True)
orderCreateDateTime = models.DateTimeField(auto_now_add=True, null=True, verbose_name='дата и время создания')
orderStatus = models.CharField(max_length=100, verbose_name='статус заказа', blank=True, null=True)
catID = models.CharField(max_length=100, verbose_name='категория', blank=True, null=True)
def get_photo_html(self, width=100, height=100, large_width=400, large_height=400):
file_id = self.orderPhoto
@ -140,3 +156,5 @@ class Orders(models.Model):
verbose_name_plural = 'Заказы'
managed = False
db_table = 'orders'

Loading…
Cancel
Save