Skip to content

Commit

Permalink
Merge pull request #1 from CodeWizardette/main
Browse files Browse the repository at this point in the history
Django- html
  • Loading branch information
timaydin committed Aug 17, 2023
2 parents ded1fa4 + 8ddbd6f commit a29a50c
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 0 deletions.
Empty file added envanter/envanter/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions envanter/envanter/admins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib import admin
from .models import Category, Component, Manufacturer

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'description')

@admin.register(Component)
class ComponentAdmin(admin.ModelAdmin):
list_display = ('model', 'manufacturer', 'category', 'stock')

@admin.register(Manufacturer)
class ManufacturerAdmin(admin.ModelAdmin):
list_display = ('name',)
16 changes: 16 additions & 0 deletions envanter/envanter/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for envanter 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/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envanter.settings')

application = get_asgi_application()
104 changes: 104 additions & 0 deletions envanter/envanter/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from django.db import models

class Category(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
description = models.CharField(max_length=500, null=True, blank=True)
parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True)

def __str__(self):
return self.name

class DocumentType(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class Document(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
description = models.CharField(max_length=500, null=True, blank=True)
document_type = models.ForeignKey(DocumentType, on_delete=models.CASCADE)
document_path = models.CharField(max_length=500)

def __str__(self):
return self.name

class Manufacturer(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class Package(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class LocationType(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class Location(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
location_type = models.ForeignKey(LocationType, on_delete=models.CASCADE)
parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True)

def __str__(self):
return self.name

class Supplier(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class Purchase(models.Model):
id = models.AutoField(primary_key=True)
date = models.DateField()
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE)

def __str__(self):
return f"Purchase #{self.id}"

class Component(models.Model):
id = models.AutoField(primary_key=True)
model = models.CharField(max_length=100)
description = models.CharField(max_length=500, null=True, blank=True)
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.SET_NULL, null=True, blank=True)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True)
package = models.ForeignKey(Package, on_delete=models.SET_NULL, null=True, blank=True)
location = models.ForeignKey(Location, on_delete=models.SET_NULL, null=True, blank=True)
stock = models.IntegerField(default=0)

def __str__(self):
return self.model

class ComponentDocumentLink(models.Model):
id = models.AutoField(primary_key=True)
document = models.ForeignKey(Document, on_delete=models.CASCADE)
component = models.ForeignKey(Component, on_delete=models.CASCADE)

def __str__(self):
return f"Link #{self.id}"

class PurchaseDetail(models.Model):
id = models.AutoField(primary_key=True)
purchase = models.ForeignKey(Purchase, on_delete=models.CASCADE)
component = models.ForeignKey(Component, on_delete=models.CASCADE)
quantity = models.IntegerField()
cost = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
total_cost = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)

def __str__(self):
return f"Purchase Detail #{self.id}"
125 changes: 125 additions & 0 deletions envanter/envanter/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""
Django settings for envanter project.
Generated by 'django-admin startproject' using Django 3.2.18.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# 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/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-g^zt7awo6vy6+dl#bmqhw7mxbz84bdtr-^cj2)f=di8$33q7g3'

# 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',
]

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 = 'envanter.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'envanter.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.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/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
78 changes: 78 additions & 0 deletions envanter/envanter/teplates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Envo</title>
<style>
/* Basit bir stil ekleyebilirsiniz */
body {
font-family: Arial, sans-serif;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Envanter</h1>

<h2>Kategoriler</h2>
<ul>
{% for category in categories %}
<li>{{ category.name }}</li>
{% endfor %}
</ul>

<h2>Parçalar</h2>
<ul>
{% for component in components %}
<li>
{{ component.model }} - {{ component.description }}
<a href="/parca/{{ component.id }}">Detaylar</a>
<a href="/parca_duzenle/{{ component.id }}">Düzenle</a>
<a href="/parca_sil/{{ component.id }}">Sil</a>
</li>
{% endfor %}
</ul>

<h2>Yeni Parça Ekle</h2>
<form action="/parca_ekle" method="post">
<label for="model">Model:</label>
<input type="text" id="model" name="model" required><br>

<label for="description">Açıklama:</label>
<input type="text" id="description" name="description"><br>

<!-- Diğer parça özellikleri için input alanları ekleyebilirsiniz -->

<button type="submit">Parça Ekle</button>
</form>

<h2>Parçaları Ara</h2>
<form action="/parca_ara" method="get">
<label for="search_query">Ara:</label>
<input type="text" id="search_query" name="query" required><br>

<button type="submit">Ara</button>
</form>

<h2>Parça Detayları</h2>
{% if selected_component %}
<p>Model: {{ selected_component.model }}</p>
<p>Açıklama: {{ selected_component.description }}</p>
<!-- Diğer parça özelliklerini buraya ekleyebilirsiniz -->
<a href="/parca_duzenle/{{ selected_component.id }}">Düzenle</a>
<a href="/parca_sil/{{ selected_component.id }}">Sil</a>
{% else %}
<p>Bir parça seçilmedi.</p>
{% endif %}

<h2>Mesaj Alanı</h2>
<p>{{ message }}</p>
</body>
</html>
22 changes: 22 additions & 0 deletions envanter/envanter/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""envanter URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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.urls import path
from . import views

urlpatterns = [
path('', views.index, name='index'),
]
7 changes: 7 additions & 0 deletions envanter/envanter/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.shortcuts import render
from .models import Category, Component

def index(request):
categories = Category.objects.all()
components = Component.objects.all()
return render(request, 'index.htm', {'categories': categories, 'components': components})
16 changes: 16 additions & 0 deletions envanter/envanter/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for envanter 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/3.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envanter.settings')

application = get_wsgi_application()
Loading

0 comments on commit a29a50c

Please sign in to comment.