commit e94b4f6b7392ca2a67baa5863daf98f0fa13776d Author: ghaem aghaey Date: Tue Jul 29 23:30:29 2025 +0330 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..621ddc5 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..cce4681 --- /dev/null +++ b/Pipfile @@ -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" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..bc0ddb5 --- /dev/null +++ b/Pipfile.lock @@ -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": {} +} diff --git a/audios/9in-angle-grinder-grinding-27697.mp3 b/audios/9in-angle-grinder-grinding-27697.mp3 new file mode 100644 index 0000000..15f030a Binary files /dev/null and b/audios/9in-angle-grinder-grinding-27697.mp3 differ diff --git a/audios/ambient-noise-236388.mp3 b/audios/ambient-noise-236388.mp3 new file mode 100644 index 0000000..df9cc70 Binary files /dev/null and b/audios/ambient-noise-236388.mp3 differ diff --git a/field/__init__.py b/field/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/field/admin.py b/field/admin.py new file mode 100644 index 0000000..677a78a --- /dev/null +++ b/field/admin.py @@ -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) diff --git a/field/apps.py b/field/apps.py new file mode 100644 index 0000000..5b584a0 --- /dev/null +++ b/field/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class FieldConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'field' diff --git a/field/migrations/0001_initial.py b/field/migrations/0001_initial.py new file mode 100644 index 0000000..ef0cd14 --- /dev/null +++ b/field/migrations/0001_initial.py @@ -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')), + ], + ), + ] diff --git a/field/migrations/0002_cost_amount.py b/field/migrations/0002_cost_amount.py new file mode 100644 index 0000000..9765a79 --- /dev/null +++ b/field/migrations/0002_cost_amount.py @@ -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), + ), + ] diff --git a/field/migrations/0003_image_comment_alter_cultivation_calender_calender_and_more.py b/field/migrations/0003_image_comment_alter_cultivation_calender_calender_and_more.py new file mode 100644 index 0000000..4df2425 --- /dev/null +++ b/field/migrations/0003_image_comment_alter_cultivation_calender_calender_and_more.py @@ -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), + ), + ] diff --git a/field/migrations/0004_job_type.py b/field/migrations/0004_job_type.py new file mode 100644 index 0000000..b1b635b --- /dev/null +++ b/field/migrations/0004_job_type.py @@ -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), + ), + ] diff --git a/field/migrations/0005_remove_voice_voice_alter_job_costs_alter_job_images_and_more.py b/field/migrations/0005_remove_voice_voice_alter_job_costs_alter_job_images_and_more.py new file mode 100644 index 0000000..8b42d3e --- /dev/null +++ b/field/migrations/0005_remove_voice_voice_alter_job_costs_alter_job_images_and_more.py @@ -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/'), + ), + ] diff --git a/field/migrations/__init__.py b/field/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/field/models.py b/field/models.py new file mode 100644 index 0000000..3b09ee6 --- /dev/null +++ b/field/models.py @@ -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 diff --git a/field/serializers.py b/field/serializers.py new file mode 100644 index 0000000..bd29cea --- /dev/null +++ b/field/serializers.py @@ -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__" diff --git a/field/tests.py b/field/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/field/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/field/urls.py b/field/urls.py new file mode 100644 index 0000000..d7187eb --- /dev/null +++ b/field/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from .views import JobListView + +urlpatterns = [ + path("jobs/v1/", JobListView.as_view()), +] diff --git a/field/views.py b/field/views.py new file mode 100644 index 0000000..ac759a8 --- /dev/null +++ b/field/views.py @@ -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) diff --git a/images/download.jpg b/images/download.jpg new file mode 100644 index 0000000..fc3d971 Binary files /dev/null and b/images/download.jpg differ diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..5767e97 --- /dev/null +++ b/manage.py @@ -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() diff --git a/settings/__init__.py b/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/settings/asgi.py b/settings/asgi.py new file mode 100644 index 0000000..fd4e54c --- /dev/null +++ b/settings/asgi.py @@ -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() diff --git a/settings/settings.py b/settings/settings.py new file mode 100644 index 0000000..728ef41 --- /dev/null +++ b/settings/settings.py @@ -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" diff --git a/settings/urls.py b/settings/urls.py new file mode 100644 index 0000000..64d14a6 --- /dev/null +++ b/settings/urls.py @@ -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"))] diff --git a/settings/wsgi.py b/settings/wsgi.py new file mode 100644 index 0000000..abcd4b0 --- /dev/null +++ b/settings/wsgi.py @@ -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()