Skip to content

Commit 8a88847

Browse files
committed
add django-admin
1 parent d5e2fa0 commit 8a88847

File tree

16 files changed

+306
-1
lines changed

16 files changed

+306
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
myenv
44
processed_frames
5-
videos
5+
videos
6+
7+
.env

kafka_postgres_project/frames/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.contrib import admin
2+
from .models import Frame
3+
4+
class FrameAdmin(admin.ModelAdmin):
5+
list_display = ('frame_id', 'get_formatted_timestamp')
6+
7+
def get_formatted_timestamp(self, obj):
8+
return obj.get_formatted_timestamp()
9+
get_formatted_timestamp.short_description = 'Timestamp'
10+
11+
admin.site.register(Frame, FrameAdmin)

kafka_postgres_project/frames/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class FramesConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'frames'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.14 on 2024-07-18 14:28
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Frame',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('frame_data', models.TextField()),
19+
('timestamp', models.BigIntegerField()),
20+
],
21+
),
22+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# # Generated by Django 4.2.14 on 2024-07-18 14:37
2+
3+
# from django.db import migrations
4+
5+
6+
# class Migration(migrations.Migration):
7+
8+
# dependencies = [
9+
# ('frames', '0001_initial'),
10+
# ]
11+
12+
# operations = [
13+
# ]
14+
from django.db import migrations
15+
16+
class Migration(migrations.Migration):
17+
18+
dependencies = [
19+
('frames', '0001_initial'),
20+
]
21+
22+
operations = [
23+
migrations.RunSQL(
24+
"SELECT 1",
25+
reverse_sql="SELECT 1",
26+
),
27+
]

kafka_postgres_project/frames/migrations/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.db import models
2+
from datetime import datetime
3+
4+
class Frame(models.Model):
5+
frame_id = models.AutoField(primary_key=True)
6+
frame_data = models.TextField()
7+
timestamp = models.BigIntegerField()
8+
9+
class Meta:
10+
db_table = 'frames'
11+
12+
def __str__(self):
13+
return f"Frame {self.frame_id} at {self.get_formatted_timestamp()}"
14+
15+
def get_formatted_timestamp(self):
16+
return datetime.fromtimestamp(self.timestamp).strftime('%Y-%m-%d %H:%M:%S')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

kafka_postgres_project/kafka_postgres_project/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for kafka_postgres_project project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kafka_postgres_project.settings')
15+
16+
application = get_asgi_application()
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"""
2+
Django settings for kafka_postgres_project project.
3+
4+
Generated by 'django-admin startproject' using Django 4.2.14.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.2/ref/settings/
11+
"""
12+
13+
import os
14+
from decouple import config
15+
from pathlib import Path
16+
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = config('SECRET_KEY')
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
'frames',
37+
'django.contrib.admin',
38+
'django.contrib.auth',
39+
'django.contrib.contenttypes',
40+
'django.contrib.sessions',
41+
'django.contrib.messages',
42+
'django.contrib.staticfiles',
43+
]
44+
45+
46+
MIDDLEWARE = [
47+
'django.middleware.security.SecurityMiddleware',
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
]
55+
56+
ROOT_URLCONF = 'kafka_postgres_project.urls'
57+
58+
TEMPLATES = [
59+
{
60+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
61+
'DIRS': [],
62+
'APP_DIRS': True,
63+
'OPTIONS': {
64+
'context_processors': [
65+
'django.template.context_processors.debug',
66+
'django.template.context_processors.request',
67+
'django.contrib.auth.context_processors.auth',
68+
'django.contrib.messages.context_processors.messages',
69+
],
70+
},
71+
},
72+
]
73+
74+
WSGI_APPLICATION = 'kafka_postgres_project.wsgi.application'
75+
76+
77+
# Database
78+
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
79+
80+
# DATABASES = {
81+
# 'default': {
82+
# 'ENGINE': 'django.db.backends.sqlite3',
83+
# 'NAME': BASE_DIR / 'db.sqlite3',
84+
# }
85+
# }
86+
DATABASES = {
87+
'default': {
88+
'ENGINE': 'django.db.backends.postgresql',
89+
'NAME': 'orders_db',
90+
'USER': 'user',
91+
'PASSWORD': 'password',
92+
'HOST': 'localhost',
93+
'PORT': '5433',
94+
}
95+
}
96+
97+
98+
99+
# Password validation
100+
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
101+
102+
AUTH_PASSWORD_VALIDATORS = [
103+
{
104+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
105+
},
106+
{
107+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
108+
},
109+
{
110+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
111+
},
112+
{
113+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
114+
},
115+
]
116+
117+
118+
# Internationalization
119+
# https://docs.djangoproject.com/en/4.2/topics/i18n/
120+
121+
LANGUAGE_CODE = 'en-us'
122+
123+
TIME_ZONE = 'UTC'
124+
125+
USE_I18N = True
126+
127+
USE_TZ = True
128+
129+
130+
# Static files (CSS, JavaScript, Images)
131+
# https://docs.djangoproject.com/en/4.2/howto/static-files/
132+
133+
STATIC_URL = 'static/'
134+
135+
# Default primary key field type
136+
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
137+
138+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
URL configuration for kafka_postgres_project project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/4.2/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
from django.contrib import admin
18+
from django.urls import path
19+
20+
urlpatterns = [
21+
path('admin/', admin.site.urls),
22+
]
23+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for kafka_postgres_project project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kafka_postgres_project.settings')
15+
16+
application = get_wsgi_application()

kafka_postgres_project/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kafka_postgres_project.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)