Skip to content

Commit 8a81a6a

Browse files
committed
upload images v1
1 parent 3541d74 commit 8a81a6a

20 files changed

+571
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__pycache__
66
db.sqlite3
77
media
8+
training/static/temp/*
89

910
# Backup files #
1011
*.bak
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.0.5 on 2022-06-17 01:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('core', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='product',
15+
name='alias',
16+
field=models.CharField(help_text='Enter product alias', max_length=20, unique=True),
17+
),
18+
migrations.AlterField(
19+
model_name='score',
20+
name='number',
21+
field=models.IntegerField(help_text='Enter product score', unique=True),
22+
),
23+
]

core/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class Product(models.Model):
66
"""
77

88
name = models.CharField(max_length=20, help_text="Enter product name")
9-
alias = models.CharField(max_length=20, help_text="Enter product alias")
9+
alias = models.CharField(max_length=20, help_text="Enter product alias", unique=True)
1010

1111
class Score(models.Model):
1212
"""
1313
Score class to store score number for products
1414
"""
15-
number = models.IntegerField( help_text="Enter product score")
15+
number = models.IntegerField( help_text="Enter product score", unique=True)
1616
description = models.CharField(max_length=80, help_text="Enter product alias")

db.sqlite3

24 KB
Binary file not shown.

tina/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'django-insecure-ql+bal_34#d@dd5#yw@xjg0mz0*ix$u$8dv4g6r9yiz-3ab(k*'
2423

2524
# SECURITY WARNING: don't run with debug turned on in production!
2625
DEBUG = True
@@ -118,6 +117,7 @@
118117
# https://docs.djangoproject.com/en/4.0/howto/static-files/
119118

120119
STATIC_URL = 'static/'
120+
STATICFILES_DIRS = [ 'training/static/', 'training/static/temp/']
121121

122122
# Default primary key field type
123123
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

tina/urls.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
"""
1616
from django.contrib import admin
1717
from django.urls import path
18-
from training.views import train
18+
from training.views import train_admin, upload, train, capture, remove
1919

2020
urlpatterns = [
2121
path('admin/', admin.site.urls),
22-
path('train/', train),
22+
path('', train_admin),
23+
path('train_admin/', train_admin),
24+
path('capture/', capture, name='capture'),
25+
path('upload/', upload, name='upload'),
26+
path('train/', train, name='train'),
27+
path('remove/', remove, name='remove'),
2328
]

training/admin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
from django.contrib import admin
2+
from .models import TrainedProduct, TrainedProductPicture
3+
4+
admin.site.register(TrainedProduct)
5+
admin.site.register(TrainedProductPicture)
26

37
# Register your models here.

training/camera.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logging
2+
from random import randint
3+
from time import sleep
4+
from picamera2 import Picamera2
5+
6+
logger = logging.getLogger()
7+
8+
def take_pictures(path, qty=1, delay=1):
9+
10+
files = []
11+
12+
picam2 = Picamera2()
13+
preview_config = picam2.still_configuration()
14+
picam2.configure(preview_config)
15+
picam2.start()
16+
try:
17+
for i in range(qty):
18+
directory = path
19+
pictureName = f'/image{randint(0, 999999999)}.jpg'
20+
metadata = picam2.capture_file(str(directory) + pictureName)
21+
#print(metadata)
22+
files.append(pictureName)
23+
sleep(delay)
24+
except Exception as e:
25+
print(e)
26+
finally:
27+
picam2.close()
28+
29+
return files
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 4.0.5 on 2022-06-17 01:52
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('training', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='trainedproduct',
16+
name='picture_path',
17+
),
18+
migrations.CreateModel(
19+
name='TrainedProductPicture',
20+
fields=[
21+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('picture_path', models.CharField(help_text='File path in FS', max_length=200)),
23+
('trained_product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='training.trainedproduct')),
24+
],
25+
),
26+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.0.5 on 2022-06-17 02:53
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('training', '0002_remove_trainedproduct_picture_path_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='trainedproduct',
15+
name='time_date',
16+
field=models.DateField(auto_now=True),
17+
),
18+
]

0 commit comments

Comments
 (0)