Skip to content

Commit

Permalink
register models in django admin and add custom style
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-lixakov committed Nov 11, 2023
1 parent 40f09ec commit 98e8f40
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/distributed_db/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
# Application definition

INSTALLED_APPS = [
'djangocms_admin_style',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
]

MIDDLEWARE = [
Expand Down
Empty file added app/main/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions app/main/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib import admin

from .models import *

admin.site.register(Cinema)
admin.site.register(Country)
admin.site.register(Customer)
admin.site.register(Film)
admin.site.register(FilmGenre)
admin.site.register(Genre)
admin.site.register(Hall)
admin.site.register(ProductionCountry)
admin.site.register(Seat)
admin.site.register(Seller)
admin.site.register(Showtime)
admin.site.register(Ticket)

6 changes: 6 additions & 0 deletions app/main/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MainConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'main'
164 changes: 164 additions & 0 deletions app/main/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Generated by Django 4.2.7 on 2023-11-11 09:48

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Cinema',
fields=[
('cinema_id', models.IntegerField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=50)),
('address', models.CharField(max_length=100)),
('operating_hours_start', models.DateTimeField()),
('operating_hours_end', models.DateTimeField()),
('contact_number', models.CharField(max_length=12)),
],
options={
'db_table': 'Cinema',
'managed': False,
},
),
migrations.CreateModel(
name='Country',
fields=[
('name', models.CharField(max_length=30)),
('country_id', models.IntegerField(primary_key=True, serialize=False)),
],
options={
'db_table': 'Country',
'managed': False,
},
),
migrations.CreateModel(
name='Customer',
fields=[
('customer_id', models.IntegerField(primary_key=True, serialize=False)),
('first_name', models.CharField(blank=True, max_length=30, null=True)),
('contact_number', models.CharField(blank=True, max_length=12, null=True)),
('last_name', models.CharField(blank=True, max_length=30, null=True)),
('email', models.CharField(blank=True, max_length=50, null=True)),
],
options={
'db_table': 'Customer',
'managed': False,
},
),
migrations.CreateModel(
name='Film',
fields=[
('film_id', models.IntegerField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=50)),
('duration', models.IntegerField()),
('base_price', models.FloatField()),
],
options={
'db_table': 'Film',
'managed': False,
},
),
migrations.CreateModel(
name='Genre',
fields=[
('genre_id', models.IntegerField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=30)),
],
options={
'db_table': 'Genre',
'managed': False,
},
),
migrations.CreateModel(
name='Hall',
fields=[
('hall_id', models.IntegerField(primary_key=True, serialize=False)),
('seating_capacity', models.IntegerField()),
],
options={
'db_table': 'Hall',
'managed': False,
},
),
migrations.CreateModel(
name='Seat',
fields=[
('seat_id', models.IntegerField(primary_key=True, serialize=False)),
('seat_number', models.IntegerField()),
('row_number', models.IntegerField()),
('class_coefficient', models.FloatField()),
],
options={
'db_table': 'Seat',
'managed': False,
},
),
migrations.CreateModel(
name='Seller',
fields=[
('first_name', models.CharField(max_length=30)),
('last_name', models.CharField(blank=True, max_length=30, null=True)),
('seller_id', models.IntegerField(primary_key=True, serialize=False)),
('contact_number', models.CharField(blank=True, max_length=30, null=True)),
('hire_date', models.DateField(blank=True, null=True)),
('salary', models.FloatField(blank=True, null=True)),
('status', models.CharField(max_length=30)),
],
options={
'db_table': 'Seller',
'managed': False,
},
),
migrations.CreateModel(
name='Showtime',
fields=[
('showtime_id', models.IntegerField(primary_key=True, serialize=False)),
('start_time', models.DateTimeField()),
('end_time', models.DateTimeField()),
],
options={
'db_table': 'Showtime',
'managed': False,
},
),
migrations.CreateModel(
name='Ticket',
fields=[
('ticket_id', models.IntegerField(primary_key=True, serialize=False)),
('purchase_date', models.DateField(blank=True, null=True)),
('price', models.FloatField()),
('status', models.CharField(max_length=30)),
],
options={
'db_table': 'Ticket',
'managed': False,
},
),
migrations.CreateModel(
name='FilmGenre',
fields=[
('film', models.OneToOneField(on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='main.film')),
],
options={
'db_table': 'Film_genre',
'managed': False,
},
),
migrations.CreateModel(
name='ProductionCountry',
fields=[
('film', models.OneToOneField(on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='main.film')),
],
options={
'db_table': 'Production_country',
'managed': False,
},
),
]
Empty file added app/main/migrations/__init__.py
Empty file.
146 changes: 146 additions & 0 deletions app/main/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models


class Cinema(models.Model):
cinema_id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
address = models.CharField(max_length=100)
operating_hours_start = models.DateTimeField()
operating_hours_end = models.DateTimeField()
contact_number = models.CharField(max_length=12)

class Meta:
managed = False
db_table = 'Cinema'


class Country(models.Model):
name = models.CharField(max_length=30)
country_id = models.IntegerField(primary_key=True)

class Meta:
managed = False
db_table = 'Country'


class Customer(models.Model):
customer_id = models.IntegerField(primary_key=True)
first_name = models.CharField(max_length=30, blank=True, null=True)
contact_number = models.CharField(max_length=12, blank=True, null=True)
last_name = models.CharField(max_length=30, blank=True, null=True)
email = models.CharField(max_length=50, blank=True, null=True)

class Meta:
managed = False
db_table = 'Customer'


class Film(models.Model):
film_id = models.IntegerField(primary_key=True)
title = models.CharField(max_length=50)
duration = models.IntegerField()
base_price = models.FloatField()

class Meta:
managed = False
db_table = 'Film'


class FilmGenre(models.Model):
film = models.OneToOneField(Film, models.DO_NOTHING, primary_key=True) # The composite primary key (film_id, genre_id) found, that is not supported. The first column is selected.
genre = models.ForeignKey('Genre', models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Film_genre'
unique_together = (('film', 'genre'),)


class Genre(models.Model):
genre_id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=30)

class Meta:
managed = False
db_table = 'Genre'


class Hall(models.Model):
hall_id = models.IntegerField(primary_key=True)
seating_capacity = models.IntegerField()
cinema = models.ForeignKey(Cinema, models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Hall'


class ProductionCountry(models.Model):
film = models.OneToOneField(Film, models.DO_NOTHING, primary_key=True) # The composite primary key (film_id, country_id) found, that is not supported. The first column is selected.
country = models.ForeignKey(Country, models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Production_country'
unique_together = (('film', 'country'),)


class Seat(models.Model):
seat_id = models.IntegerField(primary_key=True)
seat_number = models.IntegerField()
row_number = models.IntegerField()
class_coefficient = models.FloatField()
hall = models.ForeignKey(Hall, models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Seat'


class Seller(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30, blank=True, null=True)
seller_id = models.IntegerField(primary_key=True)
contact_number = models.CharField(max_length=30, blank=True, null=True)
hire_date = models.DateField(blank=True, null=True)
salary = models.FloatField(blank=True, null=True)
status = models.CharField(max_length=30)
cinema = models.ForeignKey(Cinema, models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Seller'


class Showtime(models.Model):
showtime_id = models.IntegerField(primary_key=True)
start_time = models.DateTimeField()
end_time = models.DateTimeField()
hall = models.ForeignKey(Hall, models.DO_NOTHING)
film = models.ForeignKey(Film, models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Showtime'


class Ticket(models.Model):
ticket_id = models.IntegerField(primary_key=True)
purchase_date = models.DateField(blank=True, null=True)
price = models.FloatField()
status = models.CharField(max_length=30)
seller = models.ForeignKey(Seller, models.DO_NOTHING)
customer = models.ForeignKey(Customer, models.DO_NOTHING)
showtime = models.ForeignKey(Showtime, models.DO_NOTHING)
seat = models.ForeignKey(Seat, models.DO_NOTHING)

class Meta:
managed = False
db_table = 'Ticket'
3 changes: 3 additions & 0 deletions app/main/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions app/main/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
1 change: 1 addition & 0 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
asgiref==3.7.2
Django==4.2.7
sqlparse==0.4.4
djangocms-admin-style==3.2.6
mysqlclient

0 comments on commit 98e8f40

Please sign in to comment.