Added Project category

This commit is contained in:
Oliver Walters 2017-03-27 23:08:12 +11:00
parent 8229f02db6
commit 5420f83114
10 changed files with 92 additions and 0 deletions

View File

@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'part.apps.PartConfig',
'project.apps.ProjectConfig',
'stock.apps.StockConfig',
'supplier.apps.SupplierConfig',
'track.apps.TrackConfig'

View File

@ -24,5 +24,6 @@ urlpatterns = [
url(r'^part/', include('part.urls')),
url(r'^supplier/', include('supplier.urls')),
url(r'^track/', include('track.urls')),
url(r'^project/', include('project.urls')),
url(r'^admin/', admin.site.urls),
]

View File

View File

@ -0,0 +1,7 @@
from django.contrib import admin
from .models import ProjectCategory, Project, ProjectPart
admin.site.register(ProjectCategory)
admin.site.register(Project)
admin.site.register(ProjectPart)

View File

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class ProjectConfig(AppConfig):
name = 'project'

View File

@ -0,0 +1,54 @@
from __future__ import unicode_literals
from django.db import models
from InvenTree.models import InvenTreeTree
from part.models import Part
class ProjectCategory(InvenTreeTree):
""" ProjectCategory provides hierarchical organization of Project objects.
Each ProjectCategory can contain zero-or-more child categories,
and in turn can have zero-or-one parent category.
"""
class Meta:
verbose_name = "Project Category"
verbose_name_plural = "Project Categories"
class Project(models.Model):
""" A Project takes multiple Part objects.
A project can output zero-or-more Part objects
"""
name = models.CharField(max_length=100)
description = models.CharField(max_length=500, blank=True)
category = models.ForeignKey(ProjectCategory, on_delete=models.CASCADE)
def __str__(self):
return self.name
class ProjectPart(models.Model):
""" A project part associates a single part with a project
The quantity of parts required for a single-run of that project is stored.
The overage is the number of extra parts that are generally used for a single run.
"""
# Overage types
OVERAGE_PERCENT = 0
OVERAGE_ABSOLUTE = 1
part = models.ForeignKey(Part, on_delete=models.CASCADE)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
quantity = models.IntegerField()
overage = models.FloatField()
overage_type = models.IntegerField(
choices=[
(OVERAGE_PERCENT, "Percent"),
(OVERAGE_ABSOLUTE, "Absolute")
])
def __str__(self):
return "{quan} x {name}".format(
name = self.part.name,
quan = self.quantity)

View File

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

View File

@ -0,0 +1,7 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]

View File

@ -0,0 +1,5 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
def index(request):
return HttpResponse("This is the Projects page")

7
InvenTree/track/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]