InventoryItem and InventoryItemLocation models
This commit is contained in:
parent
d20b2cb3e4
commit
86e338f981
@ -1,8 +1,25 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from kspace.models import *
|
||||
|
||||
|
||||
class InventoryItemAdmin(admin.ModelAdmin):
|
||||
list_display = ('item_name', 'serial_nr', 'usable', 'owner', 'creator',)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
if getattr(obj, 'creator', None) is None:
|
||||
obj.creator = request.user
|
||||
obj.save()
|
||||
|
||||
|
||||
class InventoryItemLocationAdmin(admin.ModelAdmin):
|
||||
list_display = ('location', 'parent',)
|
||||
|
||||
class Media:
|
||||
js = ('/static/admin/js/hide_attribute.js',)
|
||||
|
||||
admin.site.register(Challenge)
|
||||
admin.site.register(ChallengeTag)
|
||||
admin.site.register(UserChallenge)
|
||||
admin.site.register(Profile)
|
||||
admin.site.register(InventoryItemLocation, InventoryItemLocationAdmin)
|
||||
admin.site.register(InventoryItem, InventoryItemAdmin)
|
||||
|
@ -2,16 +2,21 @@ from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from location_field.models.plain import PlainLocationField
|
||||
import os
|
||||
|
||||
|
||||
def get_image_path(instance, filename):
|
||||
def get_profile_image_path(instance, filename):
|
||||
return os.path.join('icons', str(instance.id), filename)
|
||||
|
||||
|
||||
def get_inventory_item_path(filename):
|
||||
return os.path.join('inventory', filename)
|
||||
|
||||
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
icon = models.ImageField(upload_to=get_image_path, default='default_icon.png')
|
||||
icon = models.ImageField(upload_to=get_profile_image_path, default='default_icon.png')
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
@ -52,3 +57,35 @@ class UserChallenge(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
user = models.ForeignKey(User)
|
||||
challenge = models.ForeignKey(Challenge)
|
||||
|
||||
|
||||
class InventoryItemLocation(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
parent = models.ForeignKey("self", blank=True, null=True)
|
||||
address = models.BooleanField(default=True)
|
||||
location = models.CharField(max_length=256)
|
||||
gps_location = PlainLocationField(based_fields=['location'], blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.location
|
||||
|
||||
|
||||
class InventoryItem(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
id_code = models.CharField(max_length=32, default='0123456789')
|
||||
serial_nr = models.CharField(max_length=32, default='0123456789')
|
||||
usable = models.BooleanField(default=True)
|
||||
fixable = models.BooleanField()
|
||||
created_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
destroyedTime = models.DateTimeField(blank=True, null=True)
|
||||
creator = models.ForeignKey(User, related_name="%(class)s_created", blank=True, null=True, editable=False)
|
||||
location = models.ForeignKey(InventoryItemLocation, blank=True, null=True)
|
||||
owner = models.ForeignKey(User, related_name="%(class)s_item", blank=True, null=True)
|
||||
value = models.IntegerField(blank=True, null=True)
|
||||
item_name = models.CharField(max_length=256)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
photo = models.ImageField(upload_to=get_inventory_item_path, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
@ -34,6 +34,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'location_field.apps.DefaultConfig',
|
||||
'kspace'
|
||||
]
|
||||
|
||||
|
BIN
media/missing_photo.png
Normal file
BIN
media/missing_photo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
21
staticfiles/admin/js/hide_attribute.js
Normal file
21
staticfiles/admin/js/hide_attribute.js
Normal file
@ -0,0 +1,21 @@
|
||||
var hide_page = false;
|
||||
django.jQuery(document).ready(function(){
|
||||
if (django.jQuery('#id_address').is(':checked')) {
|
||||
django.jQuery(".field-gps_location").show();
|
||||
hide_page=true;
|
||||
}
|
||||
else {
|
||||
django.jQuery(".field-gps_location").hide();
|
||||
hide_page=false;
|
||||
}
|
||||
|
||||
django.jQuery("#id_address").click(function(){
|
||||
hide_page = !hide_page;
|
||||
if(hide_page) {
|
||||
django.jQuery(".field-gps_location").show();
|
||||
}
|
||||
else {
|
||||
django.jQuery(".field-gps_location").hide();
|
||||
}
|
||||
})
|
||||
});
|
Reference in New Issue
Block a user