Skip to content

Commit

Permalink
statistics in admin panel (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilyas <[email protected]>
  • Loading branch information
maxim-lixakov and IlyasDevelopment authored Dec 2, 2023
1 parent 8a75686 commit cf39d45
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/distributed_db/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import os
from pathlib import Path

from dotenv import load_dotenv

load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand All @@ -32,6 +36,8 @@

INSTALLED_APPS = [
'djangocms_admin_style',
'admin_tools_stats',
'django_nvd3',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down
3 changes: 2 additions & 1 deletion app/distributed_db/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('admin_tools_stats/', include('admin_tools_stats.urls')),
]
81 changes: 74 additions & 7 deletions app/main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,82 @@ def __init__(self, model, admin_site):
super(ModelAdmin, self).__init__(model, admin_site)


admin.site.register(Cinema, ModelAdmin)
class CinemaAdmin(admin.ModelAdmin):
list_display = ['name', 'address', 'operating_hours_start', 'operating_hours_end', 'contact_number', 'total_showtimes']

def total_showtimes(self, obj):
return Showtime.objects.filter(hall__cinema=obj).count()

total_showtimes.short_description = 'Total Showtimes'


class FilmAdmin(admin.ModelAdmin):
list_display = ['title', 'duration', 'base_price', 'total_showtimes']

def total_showtimes(self, obj):
return Showtime.objects.filter(film=obj).count()

total_showtimes.short_description = 'Total Showtimes'


class HallAdmin(admin.ModelAdmin):
list_display = ['seating_capacity', 'total_showtimes', 'total_tickets_sold']

def total_showtimes(self, obj):
return Showtime.objects.filter(hall=obj).count()

def total_tickets_sold(self, obj):
return Ticket.objects.filter(showtime__hall=obj).count()

total_showtimes.short_description = 'Total showtimes'
total_tickets_sold.short_description = 'Tickets Sold'


class GenreAdmin(admin.ModelAdmin):
list_display = ['name', 'total_films']

def total_films(self, obj):
return FilmGenre.objects.filter(genre=obj).count()

total_films.short_description = 'Total films'


class SellerAdmin(admin.ModelAdmin):
list_display = ['first_name', 'last_name', 'total_tickets_sold']

def total_tickets_sold(self, obj):
return Ticket.objects.filter(seller=obj).count()

total_tickets_sold.short_description = 'Tickets sold'


class CustomerAdmin(admin.ModelAdmin):
list_display = ['first_name', 'last_name', 'total_tickets_purchased']

def total_tickets_purchased(self, obj):
return Ticket.objects.filter(customer=obj).count()

total_tickets_purchased.short_description = 'Tickets purchased'


class ProductionCountryAdmin(admin.ModelAdmin):
list_display = ['country', 'total_films']

def total_films(self, obj):
return Film.objects.filter(productioncountry=obj).count()

total_films.short_description = 'Films Total'


admin.site.register(Country, ModelAdmin)
admin.site.register(Customer, ModelAdmin)
admin.site.register(Film, ModelAdmin)
admin.site.register(Customer, CustomerAdmin)
admin.site.register(Film, FilmAdmin)
admin.site.register(FilmGenre, ModelAdmin)
admin.site.register(Genre, ModelAdmin)
admin.site.register(Hall, ModelAdmin)
admin.site.register(ProductionCountry, ModelAdmin)
admin.site.register(Genre, GenreAdmin)
admin.site.register(Hall, HallAdmin)
admin.site.register(ProductionCountry, ProductionCountryAdmin)
admin.site.register(Seat, ModelAdmin)
admin.site.register(Seller, ModelAdmin)
admin.site.register(Seller, SellerAdmin)
admin.site.register(Showtime, ModelAdmin)
admin.site.register(Ticket, ModelAdmin)
admin.site.register(Cinema, CinemaAdmin)
4 changes: 3 additions & 1 deletion app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ asgiref==3.7.2
Django==4.2.7
sqlparse==0.4.4
djangocms-admin-style==3.2.6
mysqlclient
mysqlclient
django-admin-charts
python-dotenv

0 comments on commit cf39d45

Please sign in to comment.