Initial tree support using django-tree
This commit is contained in:
parent
f8fdb07ad9
commit
9ac7a56135
|
@ -1,7 +1,7 @@
|
||||||
version: '2'
|
version: '2'
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: aidanlister/postgres-hstore
|
build: postgres-hstore
|
||||||
|
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM postgres:latest
|
||||||
|
MAINTAINER Piotr Dobrowolski
|
||||||
|
ADD create_extension.sh docker-entrypoint-initdb.d/create_extension.sh
|
|
@ -0,0 +1,12 @@
|
||||||
|
# Because both template1 and the user postgres database have already been created,
|
||||||
|
# we need to create the hstore extension in template1 and then recreate the postgres database.
|
||||||
|
#
|
||||||
|
# Running CREATE EXTENSION in both template1 and postgres can lead to
|
||||||
|
# the extensions having different eid's.
|
||||||
|
gosu postgres psql --dbname template1 <<EOSQL
|
||||||
|
CREATE EXTENSION hstore;
|
||||||
|
CREATE EXTENSION ltree;
|
||||||
|
DROP DATABASE $POSTGRES_USER;
|
||||||
|
CREATE DATABASE $POSTGRES_USER TEMPLATE template1;
|
||||||
|
EOSQL
|
||||||
|
|
|
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
|
||||||
'django_hstore',
|
'django_hstore',
|
||||||
|
'tree',
|
||||||
|
|
||||||
'storage',
|
'storage',
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,11 +14,14 @@ class ItemImageInline(admin.TabularInline):
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
class ItemAdmin(admin.ModelAdmin):
|
class ItemAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'uuid', 'props')
|
list_display = ('_name', 'uuid', 'props', 'path')
|
||||||
list_filter = ('categories',)
|
list_filter = ('categories',)
|
||||||
form = ItemForm
|
form = ItemForm
|
||||||
inlines = [ItemImageInline]
|
inlines = [ItemImageInline]
|
||||||
|
|
||||||
|
def _name(self, obj):
|
||||||
|
return '-' * obj.get_level() + '> ' + obj.name
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Item, ItemAdmin)
|
admin.site.register(Item, ItemAdmin)
|
||||||
admin.site.register(Category)
|
admin.site.register(Category)
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.1 on 2017-02-15 01:15
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import tree.fields
|
||||||
|
from tree.operations import CreateTreeTrigger
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('storage', '0001_squashed_0008_item_state'),
|
||||||
|
('tree', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='item',
|
||||||
|
name='parent',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='storage.Item'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='item',
|
||||||
|
name='path',
|
||||||
|
field=tree.fields.PathField(),
|
||||||
|
),
|
||||||
|
CreateTreeTrigger('storage.Item'),
|
||||||
|
]
|
|
@ -5,6 +5,10 @@ from django.contrib.auth.models import User
|
||||||
from django_hstore import hstore
|
from django_hstore import hstore
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from tree.fields import PathField
|
||||||
|
from tree.models import TreeModelMixin
|
||||||
|
|
||||||
|
|
||||||
STATES = (
|
STATES = (
|
||||||
('present', 'Present'),
|
('present', 'Present'),
|
||||||
('taken', 'Taken'),
|
('taken', 'Taken'),
|
||||||
|
@ -21,24 +25,31 @@ class Category(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Item(models.Model):
|
class Item(models.Model, TreeModelMixin):
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
|
|
||||||
|
parent = models.ForeignKey('self', null=True, blank=True)
|
||||||
|
path = PathField()
|
||||||
|
|
||||||
description = models.TextField(blank=True, null=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
state = models.CharField(max_length=31, choices=STATES, default=STATES[0][0])
|
state = models.CharField(max_length=31, choices=STATES, default=STATES[0][0])
|
||||||
categories = models.ManyToManyField(Category)
|
categories = models.ManyToManyField(Category, blank=True)
|
||||||
owner = models.ForeignKey(User, null=True, blank=True, related_name='owned_items')
|
owner = models.ForeignKey(User, null=True, blank=True, related_name='owned_items')
|
||||||
|
|
||||||
taken_by = models.ForeignKey(User, null=True, blank=True, related_name='taken_items')
|
taken_by = models.ForeignKey(User, null=True, blank=True, related_name='taken_items')
|
||||||
taken_on = models.DateTimeField(blank=True, null=True)
|
taken_on = models.DateTimeField(blank=True, null=True)
|
||||||
taken_until = models.DateTimeField(blank=True, null=True)
|
taken_until = models.DateTimeField(blank=True, null=True)
|
||||||
|
|
||||||
props = hstore.DictionaryField()
|
props = hstore.DictionaryField(blank=True)
|
||||||
|
|
||||||
objects = hstore.HStoreManager()
|
objects = hstore.HStoreManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return '-' * (self.get_level() or 0) + ' ' +self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('path',)
|
||||||
|
|
||||||
|
|
||||||
class ItemImage(models.Model):
|
class ItemImage(models.Model):
|
||||||
|
|
Loading…
Reference in New Issue