Compare commits

..

3 Commits

5 changed files with 10 additions and 76 deletions

View File

@ -31,5 +31,6 @@ setuptools==75.3.0
sqlparse==0.4.1
toml==0.10.2
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.2.3
wrapt==1.12.1

View File

@ -9,7 +9,6 @@ admin.site.register(parts_models.Manufacturer)
admin.site.register(parts_models.Storage)
admin.site.register(parts_models.Stock)
admin.site.register(parts_models.ComponentParameter)
admin.site.register(parts_models.PackageParameter)
admin.site.register(parts_models.ComponentParameterType)
admin.site.register(parts_models.ComponentType)
admin.site.register(parts_models.Distributor)

View File

@ -1,49 +0,0 @@
# Generated by Django 5.1.3 on 2024-11-19 20:26
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("parts", "0012_storage_verbose_name"),
]
operations = [
migrations.CreateModel(
name="PackageParameter",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
unique=True,
),
),
("value", models.FloatField(default=0)),
("text_value", models.TextField(blank=True)),
(
"package",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="parts.package"
),
),
(
"parameter_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="parts.componentparametertype",
),
),
],
options={
"ordering": ["id"],
"unique_together": {("package", "parameter_type")},
},
),
]

View File

@ -238,25 +238,24 @@ class Component(models.Model):
sum = 0
return sum
class AbstractParameter(models.Model):
class ComponentParameter(models.Model):
class Meta:
abstract = True
unique_together = ('component', 'parameter_type')
ordering = ['id']
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
component = models.ForeignKey(Component, on_delete=models.CASCADE) # A target component is required!
parameter_type = models.ForeignKey(ComponentParameterType, on_delete=models.CASCADE)
value = models.FloatField(default=0)
text_value = models.TextField(null=False, blank=True)
def _get_object_of_param(self):
return None
def __str__(self):
if self.parameter_type.parameter_type == 'F':
value = self.text_value
else:
value = str(self.value)
return str(self._get_object_of_param())+ ': '+ str(self.parameter_type) + ': ' + value
return str(self.component)+ ': '+ str(self.parameter_type) + ': ' + value
def resolved_value_as_string(self):
my_type = self.parameter_type.parameter_type
@ -271,24 +270,6 @@ class AbstractParameter(models.Model):
elif my_type == 'F':
return self.text_value
class ComponentParameter(AbstractParameter):
class Meta:
unique_together = ('component', 'parameter_type')
ordering = ['id']
component = models.ForeignKey(Component, on_delete=models.CASCADE) # A target component is required!
def _get_object_of_param(self):
return self.component
class PackageParameter(AbstractParameter):
class Meta:
unique_together = ('package', 'parameter_type')
ordering = ['id']
package = models.ForeignKey(Package, on_delete=models.CASCADE)
def _get_object_of_param(self):
return self.package
class Stock(models.Model):
class Meta:
unique_together = ('component', 'storage')

View File

@ -56,7 +56,6 @@ if get_env_value('DJANGO_FORCE_DEV_MODE', default=False) == 'True':
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', get_env_value('DJANGO_ALLOWED_HOST')]
# Application definition
INSTALLED_APPS = [
@ -239,4 +238,7 @@ CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = False
# allow detection of https behind "old" nginx
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_HSTS_SECONDS = get_env_value('DJANGO_SECURE_HSTS_SECONDS', default=120)