Challenges now connected to items and added items hidden field
This commit is contained in:
parent
8fe36ecefc
commit
47d6741493
2
.gitignore
vendored
2
.gitignore
vendored
@ -105,7 +105,7 @@ db.sqlite3
|
||||
tasks.xml
|
||||
|
||||
media/icons
|
||||
challenges/migrations
|
||||
*/migrations
|
||||
static/
|
||||
|
||||
#PyCharm files
|
||||
|
@ -12,7 +12,7 @@ class ChallengeAdmin(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):
|
||||
if getattr(obj, 'creator', None) is None:
|
||||
|
@ -33,25 +33,6 @@ class ChallengeTag(models.Model):
|
||||
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):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True, editable=False)
|
||||
name = models.CharField(max_length=64)
|
||||
@ -78,7 +59,9 @@ class InventoryItem(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
item_name = models.CharField(max_length=256)
|
||||
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)
|
||||
location = models.ForeignKey(InventoryItemLocation, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
usable = models.BooleanField(default=True)
|
||||
@ -86,7 +69,8 @@ class InventoryItem(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=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)
|
||||
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
|
||||
|
||||
|
||||
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)
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
|
@ -23,7 +23,8 @@ def challenge(request, id):
|
||||
challenge_name = request.POST['challenge_name']
|
||||
challenge_description = request.POST['challenge_discription']
|
||||
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()
|
||||
|
||||
|
||||
|
@ -8,12 +8,6 @@
|
||||
<div class="col m8">
|
||||
<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>
|
||||
|
||||
<div class="section">
|
||||
@ -25,7 +19,8 @@
|
||||
<br>
|
||||
{% endif %}
|
||||
{% if challenge.creator.profile.phone_number %}
|
||||
<div class="valign-wrapper"><i class="material-icons">phone</i> {{ challenge.creator.profile.phone_number }}</div>
|
||||
<div class="valign-wrapper"><i
|
||||
class="material-icons">phone</i> {{ challenge.creator.profile.phone_number }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -41,33 +36,31 @@
|
||||
|
||||
</ul>
|
||||
|
||||
{% if challenge.tags|length > 0 %}
|
||||
<ul class="collection with-header">
|
||||
<li class="collection-header">
|
||||
<span class="title"><b>Tags</b></span>
|
||||
<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>
|
||||
|
||||
{% 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">
|
||||
<span class="">{{ tag.name }}</span>
|
||||
<span class="">{{ item.item_name }}</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% 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 %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -9,28 +9,30 @@
|
||||
<div class="row container challenges">
|
||||
<div class="row">
|
||||
{% for item in inventory %}
|
||||
<div class="col s12 m3">
|
||||
<div class="card" style="height:350px;">
|
||||
<div class="card-content">
|
||||
<div class="row" style="height:210px;">
|
||||
<div class="col s12 m12">
|
||||
<div class="card-title"><b>{{ item.item_name }}</b></div>
|
||||
<p>Serial: {{ item.serial_nr }}</p>
|
||||
<p style="text-align: justify; max-height: 120px; overflow: auto;">{{ item.description }}</p>
|
||||
{% if not item.hidden %}
|
||||
<div class="col s12 m3">
|
||||
<div class="card" style="height:350px;">
|
||||
<div class="card-content">
|
||||
<div class="row" style="height:210px;">
|
||||
<div class="col s12 m12">
|
||||
<div class="card-title"><b>{{ item.item_name }}</b></div>
|
||||
<p>Serial: {{ item.serial_nr }}</p>
|
||||
<p style="text-align: justify; max-height: 120px; overflow: auto;">{{ item.description }}</p>
|
||||
|
||||
<div class="card-image">
|
||||
{% if item.photo %}
|
||||
<img src='/media/{{ item.photo }}'>
|
||||
{% else %}
|
||||
<img src='/media/missing_photo.png'>
|
||||
{% endif %}
|
||||
<div class="card-image">
|
||||
{% if item.photo %}
|
||||
<img src='/media/{{ item.photo }}'>
|
||||
{% else %}
|
||||
<img src='/media/missing_photo.png'>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
</div>
|
||||
</br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user