migrate to django 2.0, optimize db-behaviour
parent
d4050516ba
commit
772afa0016
|
|
@ -15,7 +15,6 @@ import os
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
|
||||||
|
|
||||||
|
|
@ -27,85 +26,81 @@ DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'parts.apps.PartsConfig',
|
'parts.apps.PartsConfig',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'django_extensions',
|
'django_extensions',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
#'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'partdoc.urls'
|
ROOT_URLCONF = 'partdoc.urls'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
'django.template.context_processors.debug',
|
'django.template.context_processors.debug',
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'partdoc.wsgi.application'
|
WSGI_APPLICATION = 'partdoc.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
'NAME': 'partdoc',
|
'NAME': 'partdoc',
|
||||||
'USER': 'partdoc',
|
'USER': 'partdoc',
|
||||||
'PASSWORD': 'secret',
|
'PASSWORD': 'secret',
|
||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
'PORT': '5432',
|
'PORT': '5432',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||||
|
|
||||||
|
|
@ -119,13 +114,10 @@ USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
STATIC_ROOT = 'static/'
|
STATIC_ROOT = 'static/'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000
|
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000
|
||||||
|
|
@ -2,39 +2,56 @@ from django.contrib import admin
|
||||||
|
|
||||||
from .models import Brand, Product, Version, Sketch, Part, Usage, BrandedPart, ProductUsage
|
from .models import Brand, Product, Version, Sketch, Part, Usage, BrandedPart, ProductUsage
|
||||||
|
|
||||||
#admin.site.register([Brand, Product, Version, Sketch, Part, Usage, BrandedPart, ProductUsage])
|
# admin.site.register([Brand, Product, Version, Sketch, Part, Usage, BrandedPart, ProductUsage])
|
||||||
admin.site.register([Brand, Product, Version, Sketch, ProductUsage])
|
admin.site.register([Brand, Product, Version, Sketch])
|
||||||
|
|
||||||
|
|
||||||
class BrandedPartInline(admin.StackedInline):
|
class BrandedPartInline(admin.StackedInline):
|
||||||
model = BrandedPart
|
model = BrandedPart
|
||||||
extra = 1
|
extra = 1
|
||||||
|
search_fields = ["number", "name"]
|
||||||
|
autocomplete_fields = ["part"]
|
||||||
|
|
||||||
|
|
||||||
class PartAdmin(admin.ModelAdmin):
|
class PartAdmin(admin.ModelAdmin):
|
||||||
inlines = [BrandedPartInline]
|
inlines = [BrandedPartInline]
|
||||||
|
search_fields = ["name"]
|
||||||
|
|
||||||
|
|
||||||
class PartInline(admin.StackedInline):
|
class PartInline(admin.StackedInline):
|
||||||
model = Part
|
model = Part
|
||||||
|
|
||||||
#class ProductUsageInline(admin.TabularInline):
|
|
||||||
# model = ProductUsage
|
|
||||||
# extra = 1
|
|
||||||
|
|
||||||
class ProductUsageInline(admin.StackedInline):
|
class ProductUsageInline(admin.StackedInline):
|
||||||
model = ProductUsage
|
model = ProductUsage
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
|
|
||||||
class UsageAdmin(admin.ModelAdmin):
|
class UsageAdmin(admin.ModelAdmin):
|
||||||
model = Usage
|
model = Usage
|
||||||
extra = 1
|
extra = 1
|
||||||
inlines = [ProductUsageInline]
|
inlines = [ProductUsageInline]
|
||||||
|
autocomplete_fields = ["part"]
|
||||||
|
search_fields = ["part_number"]
|
||||||
|
|
||||||
|
|
||||||
|
class ProductUsageAdmin(admin.ModelAdmin):
|
||||||
|
model = ProductUsage
|
||||||
|
autocomplete_fields = ["usage"]
|
||||||
|
|
||||||
|
|
||||||
class UsageInline(admin.StackedInline):
|
class UsageInline(admin.StackedInline):
|
||||||
model = Usage
|
model = Usage
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
|
|
||||||
class BrandedPartAdmin(admin.ModelAdmin):
|
class BrandedPartAdmin(admin.ModelAdmin):
|
||||||
inlines = [UsageInline]
|
inlines = [UsageInline]
|
||||||
|
search_fields = ["number"]
|
||||||
|
autocomplete_fields = ["part"]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Usage, UsageAdmin)
|
admin.site.register(Usage, UsageAdmin)
|
||||||
|
admin.site.register(ProductUsage, ProductUsageAdmin)
|
||||||
admin.site.register(Part, PartAdmin)
|
admin.site.register(Part, PartAdmin)
|
||||||
admin.site.register(BrandedPart, BrandedPartAdmin)
|
admin.site.register(BrandedPart, BrandedPartAdmin)
|
||||||
|
|
@ -9,15 +9,15 @@ class PartModel(models. Model):
|
||||||
|
|
||||||
|
|
||||||
class Brand(PartModel):
|
class Brand(PartModel):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256, db_index=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Product(PartModel):
|
class Product(PartModel):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256, db_index=True)
|
||||||
brand = models.ForeignKey(Brand)
|
brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name + " (" + self.brand.name + ")"
|
return self.name + " (" + self.brand.name + ")"
|
||||||
|
|
@ -27,8 +27,8 @@ class Sketch(PartModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = "sketches"
|
verbose_name_plural = "sketches"
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
brand = models.ForeignKey(Brand, blank=True, null=True)
|
brand = models.ForeignKey(Brand, blank=True, null=True, on_delete=models.CASCADE, db_index=True)
|
||||||
product = models.ForeignKey(Product, blank=True, null=True)
|
product = models.ForeignKey(Product, blank=True, null=True, on_delete=models.CASCADE)
|
||||||
image = models.FileField(upload_to="sketches/", blank=True, null=True)
|
image = models.FileField(upload_to="sketches/", blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
@ -45,9 +45,9 @@ class Sketch(PartModel):
|
||||||
|
|
||||||
|
|
||||||
class Version(PartModel):
|
class Version(PartModel):
|
||||||
product = models.ForeignKey(Product)
|
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
replaced_by = models.ForeignKey('self', blank=True, null=True, related_name='replaces')
|
replaced_by = models.ForeignKey('self', blank=True, null=True, related_name='replaces', on_delete=models.SET_NULL)
|
||||||
start = models.DateField(blank=True, null=True)
|
start = models.DateField(blank=True, null=True)
|
||||||
end = models.DateField(blank=True, null=True)
|
end = models.DateField(blank=True, null=True)
|
||||||
|
|
||||||
|
|
@ -59,15 +59,15 @@ class Version(PartModel):
|
||||||
|
|
||||||
|
|
||||||
class Part(PartModel):
|
class Part(PartModel):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256, db_index=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class BrandedPart(PartModel):
|
class BrandedPart(PartModel):
|
||||||
part = models.ForeignKey(Part, null=True)
|
part = models.ForeignKey(Part, null=True, on_delete=models.SET_NULL, db_index=True)
|
||||||
brand = models.ForeignKey(Brand)
|
brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
|
||||||
number = models.CharField(max_length=64, unique=True, blank=True, null=True)
|
number = models.CharField(max_length=64, unique=True, blank=True, null=True, db_index=True)
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.part.name if self.part else "--None--"
|
return self.part.name if self.part else "--None--"
|
||||||
|
|
@ -78,8 +78,8 @@ class BrandedPart(PartModel):
|
||||||
|
|
||||||
|
|
||||||
class Usage(PartModel):
|
class Usage(PartModel):
|
||||||
part = models.ForeignKey(BrandedPart)
|
part = models.ForeignKey(BrandedPart, on_delete=models.CASCADE, db_index=True)
|
||||||
sketch = models.ForeignKey(Sketch)
|
sketch = models.ForeignKey(Sketch, on_delete=models.CASCADE, db_index=True)
|
||||||
sketch_number = models.CharField(max_length=32)
|
sketch_number = models.CharField(max_length=32)
|
||||||
exact_sketch = models.BooleanField(default=True)
|
exact_sketch = models.BooleanField(default=True)
|
||||||
#quantity = models.ManyToManyField(ProductUsage)
|
#quantity = models.ManyToManyField(ProductUsage)
|
||||||
|
|
@ -91,15 +91,16 @@ class Usage(PartModel):
|
||||||
|
|
||||||
|
|
||||||
class ProductUsage(PartModel):
|
class ProductUsage(PartModel):
|
||||||
usage = models.ForeignKey(Usage, null=True)
|
usage = models.ForeignKey(Usage, null=True, on_delete=models.SET_NULL, db_index=True)
|
||||||
product = models.ForeignKey(Product)
|
product = models.ForeignKey(Product, on_delete=models.CASCADE, db_index=True)
|
||||||
quantity = models.IntegerField(null=True)
|
quantity = models.IntegerField(null=True)
|
||||||
on_demand = models.BooleanField(default=False)
|
on_demand = models.BooleanField(default=False)
|
||||||
obsolete = models.BooleanField(default=False)
|
obsolete = models.BooleanField(default=False)
|
||||||
used_until = models.ForeignKey(Version, null=True, blank=True, related_name='introduces')
|
used_until = models.ForeignKey(Version, null=True, blank=True, related_name='introduces', on_delete=models.SET_NULL)
|
||||||
used_since = models.ForeignKey(Version, null=True, blank=True, related_name='dissmisses')
|
used_since = models.ForeignKey(Version, null=True, blank=True, related_name='dissmisses', on_delete=models.SET_NULL)
|
||||||
replaced_by = models.ForeignKey('self', null=True, blank=True, related_name='replaces')
|
#replaced_by = models.ForeignKey('self', null=True, blank=True, related_name='replaces', on_delete=models.SET_NULL)
|
||||||
alternative = models.ForeignKey('self', null=True, blank=True, related_name='alternatives')
|
replaced_by = models.CharField(max_length=512, null=True, blank=True)
|
||||||
|
#alternative = models.ForeignKey('self', null=True, blank=True, related_name='alternatives', on_delete=models.SET_NULL)
|
||||||
note = models.CharField(max_length=1024, blank=True)
|
note = models.CharField(max_length=1024, blank=True)
|
||||||
internal_note = models.CharField(max_length=2, blank=True)
|
internal_note = models.CharField(max_length=2, blank=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
from django.conf.urls import url
|
from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
app_name = "parts"
|
app_name = "parts"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.index, name="index"),
|
path('', views.index, name="index"),
|
||||||
url(r'^product/(?P<product_id>[0-9]+)/$', views.product, name="detail"),
|
path('product/<int:product_id>/', views.product, name="detail"),
|
||||||
url(r'^sketch/(?P<sketch_id>[0-9]+)/$', views.sketch, name="sketch"),
|
path('sketch/<int:sketch_id>/', views.sketch, name="sketch"),
|
||||||
url(r'^add/(?P<product_id>[0-9]+)/sketch/(?P<sketch_id>[0-9]+)', views.sketch_add, name="continue_sketch"),
|
path('add/<int:product_id>/sketch/<int:sketch_id>', views.sketch_add, name="continue_sketch"),
|
||||||
url(r'^add/(?P<product_id>[0-9]+)/sketch', views.sketch_add, name="new_sketch"),
|
path('add/<int:product_id>/sketch', views.sketch_add, name="new_sketch"),
|
||||||
url(r'^search/part/$', views.part_search, name="part_search"),
|
path('search/part/', views.part_search, name="part_search"),
|
||||||
]
|
]
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
django==2.0.1
|
||||||
|
psycopg2==2.7.3.2
|
||||||
|
django-extensions==1.9.9
|
||||||
Loading…
Reference in New Issue