Initial Commit

This commit is contained in:
2025-07-29 23:30:29 +03:30
commit e94b4f6b73
26 changed files with 714 additions and 0 deletions

89
.gitignore vendored Normal file
View File

@@ -0,0 +1,89 @@
# Created by https://www.gitignore.io
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Sphinx documentation
docs/_build/
# PyBuilder
target/
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
.env
db.sqlite3

17
Pipfile Normal file
View File

@@ -0,0 +1,17 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
djangorestframework = "*"
djangorestframework-jwt = "*"
psycopg2 = "*"
python-dotenv = "*"
pillow = "*"
[dev-packages]
[requires]
python_version = "3.13"

20
Pipfile.lock generated Normal file
View File

@@ -0,0 +1,20 @@
{
"_meta": {
"hash": {
"sha256": "494d5b4f482f0ef471f49afe28f00ec1a2ff75da2ce65060d8cabaeb3da2f100"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.13"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {},
"develop": {}
}

Binary file not shown.

Binary file not shown.

0
field/__init__.py Normal file
View File

13
field/admin.py Normal file
View File

@@ -0,0 +1,13 @@
from django.contrib import admin
# Register your models here.
from .models import Cost, Cultivation_calender, Field, Image, Job, Note, Product, Voice
admin.site.register(Cost)
admin.site.register(Cultivation_calender)
admin.site.register(Field)
admin.site.register(Image)
admin.site.register(Job)
admin.site.register(Note)
admin.site.register(Product)
admin.site.register(Voice)

6
field/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class FieldConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'field'

View File

@@ -0,0 +1,83 @@
# Generated by Django 5.2.4 on 2025-07-29 17:23
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Cost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Cultivation_calender',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('calender', models.JSONField()),
],
),
migrations.CreateModel(
name='Field',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('geography', models.JSONField()),
],
),
migrations.CreateModel(
name='Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(upload_to='images/')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Note',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
],
),
migrations.CreateModel(
name='Voice',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('Voice', models.FileField(upload_to='audios/')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('cultivation_days', models.IntegerField()),
('cultivation_calender', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='field.cultivation_calender')),
],
),
migrations.CreateModel(
name='Job',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('made_date', models.DateTimeField(auto_now_add=True)),
('due_date', models.DateTimeField()),
('status', models.BooleanField()),
('costs', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='field.cost')),
('field', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='field.field')),
('images', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='field.image')),
('notes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='field.note')),
('voices', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='field.voice')),
],
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.4 on 2025-07-29 17:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('field', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='cost',
name='amount',
field=models.BigIntegerField(default=0),
),
]

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.2.4 on 2025-07-29 17:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('field', '0002_cost_amount'),
]
operations = [
migrations.AddField(
model_name='image',
name='comment',
field=models.TextField(default=''),
),
migrations.AlterField(
model_name='cultivation_calender',
name='calender',
field=models.JSONField(default=dict),
),
migrations.AlterField(
model_name='field',
name='geography',
field=models.JSONField(default=dict),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.4 on 2025-07-29 17:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('field', '0003_image_comment_alter_cultivation_calender_calender_and_more'),
]
operations = [
migrations.AddField(
model_name='job',
name='type',
field=models.CharField(choices=[('Irrigating', 'IRRIGATING'), ('Planting', 'PLANTING'), ('PrePlanting', 'PREPLANTING'), ('Fertilizing', 'FERTILIZING'), ('Pruning', 'PRUNING'), ('Harvesting', 'HARVESTING')], default='Irrigating', max_length=15),
),
]

View File

@@ -0,0 +1,43 @@
# Generated by Django 5.2.4 on 2025-07-29 18:30
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('field', '0004_job_type'),
]
operations = [
migrations.RemoveField(
model_name='voice',
name='Voice',
),
migrations.AlterField(
model_name='job',
name='costs',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='field.cost'),
),
migrations.AlterField(
model_name='job',
name='images',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='field.image'),
),
migrations.AlterField(
model_name='job',
name='notes',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='field.note'),
),
migrations.AlterField(
model_name='job',
name='voices',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='field.voice'),
),
migrations.AddField(
model_name='voice',
name='voice',
field=models.FileField(blank=True, null=True, upload_to='audios/'),
),
]

View File

83
field/models.py Normal file
View File

@@ -0,0 +1,83 @@
from django.db import models
# Create your models here.
class Field(models.Model):
name = models.CharField(max_length=255)
geography = models.JSONField(default=dict)
def __str__(self):
return self.name
class Note(models.Model):
content = models.TextField()
def __str__(self):
return self.content[:60]
class Cost(models.Model):
name = models.CharField(max_length=255)
amount = models.BigIntegerField(default=0)
def __str__(self):
return self.name
class Image(models.Model):
image = models.ImageField(upload_to="images/")
comment = models.TextField(default="")
uploaded_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.image.name
class Voice(models.Model):
voice = models.FileField(upload_to="audios/", null=True, blank=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
if self.voice.name:
return self.voice.name
else:
return "null"
class Job(models.Model):
TYPE_CHOICES = [
("Irrigating", "IRRIGATING"),
("Planting", "PLANTING"),
("PrePlanting", "PREPLANTING"),
("Fertilizing", "FERTILIZING"),
("Pruning", "PRUNING"),
("Harvesting", "HARVESTING"),
]
type = models.CharField(max_length=15, choices=TYPE_CHOICES, default="Irrigating")
field = models.ForeignKey(Field, on_delete=models.CASCADE)
made_date = models.DateTimeField(auto_now_add=True)
due_date = models.DateTimeField()
status = models.BooleanField()
costs = models.ForeignKey(Cost, on_delete=models.SET_NULL, null=True, blank=True)
notes = models.ForeignKey(Note, on_delete=models.SET_NULL, null=True, blank=True)
voices = models.ForeignKey(Voice, on_delete=models.SET_NULL, null=True, blank=True)
images = models.ForeignKey(Image, on_delete=models.SET_NULL, null=True, blank=True)
def __str__(self):
return self.type
class Cultivation_calender(models.Model):
calender = models.JSONField(default=dict)
class Product(models.Model):
name = models.CharField(max_length=255)
cultivation_days = models.IntegerField()
cultivation_calender = models.OneToOneField(
Cultivation_calender, on_delete=models.CASCADE
)
def __str__(self):
return self.name

58
field/serializers.py Normal file
View File

@@ -0,0 +1,58 @@
from rest_framework import serializers
from .models import Field, Note, Cost, Image, Voice, Job, Cultivation_calender, Product
class FieldSerializer(serializers.ModelSerializer):
class Meta:
model = Field
fields = "__all__"
class NoteSerializer(serializers.ModelSerializer):
class Meta:
model = Note
fields = "__all__"
class CostSerializer(serializers.ModelSerializer):
class Meta:
model = Cost
fields = "__all__"
class ImageSerializer(serializers.ModelSerializer):
class Meta:
model = Image
fields = "__all__"
class VoiceSerializer(serializers.ModelSerializer):
class Meta:
model = Voice
fields = "__all__"
class JobSerializer(serializers.ModelSerializer):
field = FieldSerializer()
costs = CostSerializer()
notes = NoteSerializer()
voices = VoiceSerializer()
images = ImageSerializer()
class Meta:
model = Job
fields = "__all__"
class CultivationCalenderSerializer(serializers.ModelSerializer):
class Meta:
model = Cultivation_calender
fields = "__all__"
class ProductSerializer(serializers.ModelSerializer):
cultivation_calender = CultivationCalenderSerializer()
class Meta:
model = Product
fields = "__all__"

3
field/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
field/urls.py Normal file
View File

@@ -0,0 +1,6 @@
from django.urls import path
from .views import JobListView
urlpatterns = [
path("jobs/v1/", JobListView.as_view()),
]

15
field/views.py Normal file
View File

@@ -0,0 +1,15 @@
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Job
from .serializers import JobSerializer
from rest_framework.viewsets import ModelViewSet
# Create your views here.
class JobListView(APIView):
def get(self, request):
jobs = Job.objects.all()
serilizer = JobSerializer(jobs, many=True)
return Response(serilizer.data)

BIN
images/download.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

22
manage.py Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

0
settings/__init__.py Normal file
View File

16
settings/asgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
ASGI config for settings project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.settings')
application = get_asgi_application()

139
settings/settings.py Normal file
View File

@@ -0,0 +1,139 @@
"""
Django settings for settings project.
Generated by 'django-admin startproject' using Django 5.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""
from pathlib import Path
from dotenv import load_dotenv
import os
load_dotenv()
# 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/5.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-so1ts^_(*t1rlr172801d%6o66$!#)^vc^9_)1n1wh*a5j9w#7"
# 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",
"rest_framework",
"field",
]
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 = "settings.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "settings.wsgi.application"
# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "finka",
"USER": "finkaadmin",
"PASSWORD": os.getenv("DATABASEPASSWORD"),
"HOST": "localhost", # Or your PostgreSQL server's IP/hostname
"PORT": "5432",
}
}
# Password validation
# https://docs.djangoproject.com/en/5.2/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/5.2/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/5.2/howto/static-files/
STATIC_URL = "static/"
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

21
settings/urls.py Normal file
View File

@@ -0,0 +1,21 @@
"""
URL configuration for settings project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [path("admin/", admin.site.urls), path("", include("field.urls"))]

16
settings/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for settings project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.settings')
application = get_wsgi_application()