2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 03:25:42 +00:00

Added PartCategory

- Parent can be null (top-level category)
- Parent can be other PartCategory
This commit is contained in:
Oliver Walters
2017-03-25 23:07:43 +11:00
parent 2863ea1b70
commit bb4fc9820f
10 changed files with 47 additions and 63 deletions

View File

@ -37,6 +37,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'part.apps.PartConfig'
]
MIDDLEWARE = [

View File

@ -13,9 +13,10 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^part/', include('part.urls')),
url(r'^admin/', admin.site.urls),
]

View File

5
InvenTree/part/admin.py Normal file
View File

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import PartCategory
admin.site.register(PartCategory)

7
InvenTree/part/apps.py Normal file
View File

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

14
InvenTree/part/models.py Normal file
View File

@ -0,0 +1,14 @@
from __future__ import unicode_literals
from django.db import models
class PartCategory(models.Model):
name = models.CharField(max_length=128)
description = models.CharField(max_length=512)
parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
def __str__(self):
if self.parent:
return str(self.parent) + "/" + self.name
else:
return self.name

3
InvenTree/part/tests.py Normal file
View File

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

7
InvenTree/part/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')
]

5
InvenTree/part/views.py Normal file
View File

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