Challenges now connected to items and added items hidden field

This commit is contained in:
teras 2017-12-03 15:46:54 +02:00 committed by Lauri Võsandi
parent 8fe36ecefc
commit 47d6741493
6 changed files with 70 additions and 70 deletions

2
.gitignore vendored
View File

@ -105,7 +105,7 @@ db.sqlite3
tasks.xml tasks.xml
media/icons media/icons
challenges/migrations */migrations
static/ static/
#PyCharm files #PyCharm files

View File

@ -12,7 +12,7 @@ class ChallengeAdmin(admin.ModelAdmin):
class InventoryItemAdmin(admin.ModelAdmin): class InventoryItemAdmin(admin.ModelAdmin):
list_display = ('item_name', 'serial_nr', 'usable', 'owner', 'creator',) list_display = ('item_name', 'serial_nr', 'hidden', 'usable', 'owner', 'creator',)
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
if getattr(obj, 'creator', None) is None: if getattr(obj, 'creator', None) is None:

View File

@ -33,25 +33,6 @@ class ChallengeTag(models.Model):
return self.name return self.name
class Challenge(models.Model):
id = models.AutoField(primary_key=True)
creator = models.ForeignKey(User, blank=True, null=True, editable=False, on_delete=models.SET_NULL)
name = models.CharField(max_length=64)
blurb = models.CharField(max_length=140, blank=True, null=True )
description = models.TextField(blank=True, null=True)
tags = models.ManyToManyField(ChallengeTag, blank=True)
recurring = models.BooleanField(default=False)
def __str__(self):
return self.name
class UserChallenge(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL)
challenge = models.ForeignKey(Challenge, blank=True, null=True, on_delete=models.SET_NULL)
class InventoryItemOwner(models.Model): class InventoryItemOwner(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True, editable=False) user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True, editable=False)
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
@ -78,7 +59,9 @@ class InventoryItem(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
item_name = models.CharField(max_length=256) item_name = models.CharField(max_length=256)
serial_nr = models.CharField(max_length=32, default='', blank=True, null=True) serial_nr = models.CharField(max_length=32, default='', blank=True, null=True)
owner = models.ForeignKey(InventoryItemOwner , related_name="%(class)s_item", blank=True, null=True, on_delete=models.SET_NULL) hidden = models.BooleanField(default=True)
owner = models.ForeignKey(InventoryItemOwner, related_name="%(class)s_item", blank=True, null=True,
on_delete=models.SET_NULL)
value = models.IntegerField(blank=True, null=True) value = models.IntegerField(blank=True, null=True)
location = models.ForeignKey(InventoryItemLocation, blank=True, null=True, on_delete=models.SET_NULL) location = models.ForeignKey(InventoryItemLocation, blank=True, null=True, on_delete=models.SET_NULL)
usable = models.BooleanField(default=True) usable = models.BooleanField(default=True)
@ -86,7 +69,8 @@ class InventoryItem(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True) updated = models.DateTimeField(auto_now=True)
destroyed = models.DateTimeField(blank=True, null=True) destroyed = models.DateTimeField(blank=True, null=True)
creator = models.ForeignKey(User, related_name="%(class)s_created", blank=True, null=True, editable=False, on_delete=models.SET_NULL) creator = models.ForeignKey(User, related_name="%(class)s_created", blank=True, null=True, editable=False,
on_delete=models.SET_NULL)
description = models.TextField(blank=True, null=True) description = models.TextField(blank=True, null=True)
photo = models.ImageField(upload_to=get_inventory_item_path, blank=True, null=True) photo = models.ImageField(upload_to=get_inventory_item_path, blank=True, null=True)
@ -94,6 +78,26 @@ class InventoryItem(models.Model):
return self.item_name return self.item_name
class Challenge(models.Model):
id = models.AutoField(primary_key=True)
creator = models.ForeignKey(User, blank=True, null=True, editable=False, on_delete=models.SET_NULL)
name = models.CharField(max_length=64)
blurb = models.CharField(max_length=140, blank=True, null=True)
description = models.TextField(blank=True, null=True)
required_items = models.ManyToManyField(InventoryItem, blank=True)
tags = models.ManyToManyField(ChallengeTag, blank=True)
recurring = models.BooleanField(default=False)
def __str__(self):
return self.name
class UserChallenge(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL)
challenge = models.ForeignKey(Challenge, blank=True, null=True, on_delete=models.SET_NULL)
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs): def create_user_profile(sender, instance, created, **kwargs):
if created: if created:

View File

@ -23,7 +23,8 @@ def challenge(request, id):
challenge_name = request.POST['challenge_name'] challenge_name = request.POST['challenge_name']
challenge_description = request.POST['challenge_discription'] challenge_description = request.POST['challenge_discription']
tags = [] tags = []
new_challenge = Challenge(creator=request.user, name=challenge_name, description=challenge_description, tags=tags) new_challenge = Challenge(creator=request.user, name=challenge_name, description=challenge_description,
tags=tags)
new_challenge.save() new_challenge.save()

View File

@ -8,12 +8,6 @@
<div class="col m8"> <div class="col m8">
<h3 class="">{{ challenge.name }}</h3> <h3 class="">{{ challenge.name }}</h3>
<div>
{% for tag in challenge.tags.all %}
<div class="chip">{{ tag.name }}</div>
{% endfor %}
</div>
<p style="">{{ challenge.description | markdownify }}</p> <p style="">{{ challenge.description | markdownify }}</p>
<div class="section"> <div class="section">
@ -25,7 +19,8 @@
<br> <br>
{% endif %} {% endif %}
{% if challenge.creator.profile.phone_number %} {% if challenge.creator.profile.phone_number %}
<div class="valign-wrapper"><i class="material-icons">phone</i>&nbsp;{{ challenge.creator.profile.phone_number }}</div> <div class="valign-wrapper"><i
class="material-icons">phone</i>&nbsp;{{ challenge.creator.profile.phone_number }}</div>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@ -41,33 +36,31 @@
</ul> </ul>
{% if challenge.tags|length > 0 %} <ul class="collection with-header">
<ul class="collection with-header"> <li class="collection-header">
<li class="collection-header"> <span class="title"><b>Tags</b></span>
<span class="title"><b>Tags</b></span> </li>
{% for tag in challenge.tags.all %}
<li class="collection-item">
<span class="">{{ tag.name }}</span>
</li> </li>
{% endfor %}
</ul>
{% for tag in challenge.tags.all %} <ul class="collection with-header">
<li class="collection-header">
<span class="title"><b>Inventory Items</b></span>
</li>
{% for item in challenge.required_items.all %}
{% if not item.hidden %}
<li class="collection-item"> <li class="collection-item">
<span class="">{{ tag.name }}</span> <span class="">{{ item.item_name }}</span>
</li> </li>
{% endfor %} {% endif %}
</ul> {% endfor %}
{% endif %} </ul>
{% if challenge.tags|length > 0 %}
<ul class="collection with-header">
<li class="collection-header">
<span class="title"><b>Tags</b></span>
</li>
{% for tag in challenge.tags.all %}
<li class="collection-item">
<span class="">{{ tag.name }}</span>
</li>
{% endfor %}
</ul>
{% endif %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -9,28 +9,30 @@
<div class="row container challenges"> <div class="row container challenges">
<div class="row"> <div class="row">
{% for item in inventory %} {% for item in inventory %}
<div class="col s12 m3"> {% if not item.hidden %}
<div class="card" style="height:350px;"> <div class="col s12 m3">
<div class="card-content"> <div class="card" style="height:350px;">
<div class="row" style="height:210px;"> <div class="card-content">
<div class="col s12 m12"> <div class="row" style="height:210px;">
<div class="card-title"><b>{{ item.item_name }}</b></div> <div class="col s12 m12">
<p>Serial: {{ item.serial_nr }}</p> <div class="card-title"><b>{{ item.item_name }}</b></div>
<p style="text-align: justify; max-height: 120px; overflow: auto;">{{ item.description }}</p> <p>Serial: {{ item.serial_nr }}</p>
<p style="text-align: justify; max-height: 120px; overflow: auto;">{{ item.description }}</p>
<div class="card-image"> <div class="card-image">
{% if item.photo %} {% if item.photo %}
<img src='/media/{{ item.photo }}'> <img src='/media/{{ item.photo }}'>
{% else %} {% else %}
<img src='/media/missing_photo.png'> <img src='/media/missing_photo.png'>
{% endif %} {% endif %}
</div>
</div> </div>
</div> </div>
</br>
</div> </div>
</br>
</div> </div>
</div> </div>
</div> {% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>