2016-09-29 20:20:10 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django_hstore import hstore
|
|
|
|
import uuid
|
|
|
|
|
2017-02-15 03:01:47 +00:00
|
|
|
from tree.fields import PathField
|
|
|
|
from tree.models import TreeModelMixin
|
|
|
|
|
|
|
|
|
2016-09-29 20:20:10 +00:00
|
|
|
STATES = (
|
|
|
|
('present', 'Present'),
|
|
|
|
('taken', 'Taken'),
|
|
|
|
('broken', 'Broken'),
|
|
|
|
('missing', 'Missing'),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
class Category(models.Model):
|
|
|
|
name = models.CharField(max_length=127)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2017-02-15 03:01:47 +00:00
|
|
|
class Item(models.Model, TreeModelMixin):
|
2016-09-29 20:20:10 +00:00
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
2017-02-15 03:01:47 +00:00
|
|
|
|
|
|
|
parent = models.ForeignKey('self', null=True, blank=True)
|
|
|
|
path = PathField()
|
|
|
|
|
2017-02-16 15:14:37 +00:00
|
|
|
name = models.TextField()
|
|
|
|
|
2016-09-29 20:20:10 +00:00
|
|
|
description = models.TextField(blank=True, null=True)
|
|
|
|
state = models.CharField(max_length=31, choices=STATES, default=STATES[0][0])
|
2017-02-15 03:01:47 +00:00
|
|
|
categories = models.ManyToManyField(Category, blank=True)
|
2016-09-29 20:20:10 +00:00
|
|
|
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_on = models.DateTimeField(blank=True, null=True)
|
|
|
|
taken_until = models.DateTimeField(blank=True, null=True)
|
|
|
|
|
2017-02-15 03:01:47 +00:00
|
|
|
props = hstore.DictionaryField(blank=True)
|
2016-09-29 20:20:10 +00:00
|
|
|
|
|
|
|
objects = hstore.HStoreManager()
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-02-16 01:01:36 +00:00
|
|
|
return '- ' * (self.get_level() or 0) + self.name
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
from django.urls import reverse
|
|
|
|
return reverse('item-display', kwargs={'pk': str(self.pk)})
|
2017-02-15 03:01:47 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('path',)
|
2016-09-29 20:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ItemImage(models.Model):
|
|
|
|
item = models.ForeignKey(Item, related_name='images')
|
|
|
|
image = models.ImageField()
|