VI.Ilova
from django.shortcuts import render, redirect
from django.db.models import Sum
from .models import *
def about(request):
return render(request, 'about.html')
def club(request):
data = {'club': Club.objects.annotate(umum_summa=Sum('futbolchilari__tr_narxi')).order_by('-umum_summa')}
return render(request, 'clubs.html', data)
def player(request):
data = {'player':Player.objects.all().order_by('-tr_narxi')}
return render(request, 'players.html', data)
def latest_transfer(request):
data = {'trans': Transfer.objects.order_by('-narxi')}
return render(request, 'latest-transfers.html', data)
def davlat(request,soz):
data = {'davlat':Club.objects.filter(davlat=soz),
'mamlakat':soz}
return render(request, 'england.html', data)
def u20(request):
from datetime import date, timedelta
bugun = date.today()
boshi = bugun - timedelta(days=20*365)
pl = Player.objects.filter(t_yil__range=[boshi, bugun])
data = {
'players':pl,
'h_yil': bugun.year
}
return render(request, 'U-20 players.html', data)
def arxive(request):
h_mavsum = Hozirgi_mavsum.objects.last().hozirgi_mavsum
data = {
'Transferlar': Transfer.objects.filter(mavsum__lt=h_mavsum).values('mavsum').distinct().order_by('-mavsum')
}
return render(request, 'transfer-archive.html', data)
def bitta_mavsum(request, soz):
data = {
'mavsumgaoid': Transfer.objects.filter(mavsum=soz)
}
return render(request, '2017-18season.html', data)
def bitta_club(request,son):
data = {
'club': Player.objects.filter(club=Club.objects.get(id=son))
}
return render(request, 'country-clubs.html', data)
def stats(request):
return render(request, 'stats.html')
def transfer_record(request):
data = {
'tra': Transfer.objects.filter(narxi__gt=50).order_by('-narxi')[0:100]
}
return render(request, 'transfer-records.html', data)
from django.db import models
class Club(models.Model):
nom = models.CharField(max_length=100)
davlat = models.CharField(max_length=100)
logo = models.FileField()
president = models.CharField(max_length=100)
coach = models.CharField(max_length=80)
yili = models.CharField(max_length=30)
eng_qim_tr = models.CharField(max_length=50)
eng_qim_sotuv = models.CharField(max_length=50)
def __str__(self):
return self.nom
class Player(models.Model):
pozit = [
('Midfielder', 'Midfielder'),
('Defender', 'Defender'),
('Forward', 'Forward'),
('Keeper', 'Keeper')
]
ism = models.CharField(max_length=50)
t_yil = models.DateField()
club = models.ForeignKey(Club, on_delete=models.CASCADE, related_name='futbolchilari')
tr_narxi = models.PositiveIntegerField()
millat = models.CharField(max_length=50)
pozitsiya = models.CharField(max_length=50, choices=pozit)
def __str__(self):
return self.ism
class Transfer(models.Model):
player = models.ForeignKey(Player, on_delete=models.CASCADE)
eski = models.ForeignKey(Club, on_delete=models.CASCADE, related_name='sotuvlari')
yangi = models.ForeignKey(Club, on_delete=models.CASCADE, related_name='sotib_olganlari')
narxi = models.PositiveIntegerField()
tax_narxi = models.PositiveIntegerField()
mavsum = models.CharField(max_length=40)
def __str__(self):
return f'{self.player}'
class Hozirgi_mavsum(models.Model):
hozirgi_mavsum = models.CharField(max_length=100)
def __str__(self):
return self.hozirgi_mavsum
from django.contrib import admin
from .models import *
@admin.register(Club)
class ClubAdmin(admin.ModelAdmin):
list_display = ( 'nom', 'davlat')
list_filter = ('davlat',)
search_fields = ('nom', 'davlat')
@admin.register(Player)
class PlayerAdmin(admin.ModelAdmin):
list_display = ('ism', 'club')
list_filter = ('club',)
search_fields = ('ism',)
autocomplete_fields = ('club',)
@admin.register(Transfer)
class TransferAdmin(admin.ModelAdmin):
list_display = ('player', 'eski', 'yangi', 'mavsum', 'narxi')
list_filter = ('mavsum',)
search_fields = ('mavsum', 'narxi',)
autocomplete_fields = ('player','eski', 'yangi')
admin.site.register(Hozirgi_mavsum)
"""
Django settings for transfer project.
Generated by 'django-admin startproject' using Django 4.1.3.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-b565fdulf&7hs-ld4a(*x+-rvi!y%dl_z)gyxu7_fdk7gx8!(v'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'asosiy',
'mathfilters',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'transfer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR/'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'transfer.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR/'static']
MEDIA_ROOT = BASE_DIR/'media/'
MEDIA_URL = 'media/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from asosiy.views import *
urlpatterns = [
path('admin/', admin.site.urls),
path('', about),
path('club/', club),
path('player/', player),
path('latest-transfers/', latest_transfer),
path('countries//', davlat),
path('mavsum//', bitta_mavsum),
path('playeru20/', u20),
path('stats/', stats),
path('transfer_record/', transfer_record),
path('transfer-archive/', arxive),
path('clubs//', bitta_club),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
{% extends 'header.html' %}
{%block content %}
|