rename the field 'binary_availability' to 'do_not_count' in model Drink
This commit is contained in:
parent
b7e9673267
commit
ec7672816a
6 changed files with 11 additions and 10 deletions
|
@ -66,7 +66,7 @@ class CustomDrinkAdmin(admin.ModelAdmin):
|
|||
|
||||
model = Drink
|
||||
form = CustomDrinkForm
|
||||
list_display = ["product_name", "content_litres", "price", "available", "binary_availability", "deleted"]
|
||||
list_display = ["product_name", "content_litres", "price", "available", "do_not_count", "deleted"]
|
||||
|
||||
adminSite.register(Drink, CustomDrinkAdmin)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class CustomDrinkForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Drink
|
||||
fields = ("product_name", "content_litres", "price", "binary_availability", "available", "deleted")
|
||||
fields = ("product_name", "content_litres", "price", "do_not_count", "available", "deleted")
|
||||
|
||||
|
||||
class CustomRegisterTransactionForm(forms.ModelForm):
|
||||
|
|
|
@ -41,10 +41,11 @@ class Drink(models.Model):
|
|||
available = models.PositiveIntegerField(default=0)
|
||||
deleted = models.BooleanField(default=False)
|
||||
|
||||
# when the following field is true:
|
||||
# when the following field is true, the amount of drinks will
|
||||
# not change and will not be displayed.
|
||||
# available > 0 -> there is a indefinetly amount of drinks left
|
||||
# available < 1 -> there are no drinks left
|
||||
binary_availability = models.BooleanField(default=False)
|
||||
do_not_count = models.BooleanField(default=False)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.deleted = True
|
||||
|
@ -123,7 +124,7 @@ class Order(models.Model):
|
|||
def save(self, *args, **kwargs):
|
||||
drink = Drink.objects.get(pk=self.drink.pk)
|
||||
if self._state.adding and drink.available > 0:
|
||||
if not drink.binary_availability:
|
||||
if not drink.do_not_count:
|
||||
drink.available -= self.amount
|
||||
drink.save()
|
||||
self.product_name = drink.product_name
|
||||
|
@ -139,7 +140,7 @@ class Order(models.Model):
|
|||
self.user.balance += self.price_sum
|
||||
self.user.save()
|
||||
drink = Drink.objects.get(pk=self.drink.pk)
|
||||
if not drink.binary_availability:
|
||||
if not drink.do_not_count:
|
||||
drink.available += self.amount
|
||||
drink.save()
|
||||
super().delete(*args, **kwargs)
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
<ul class="availableDrinksList">
|
||||
{% for drink in available_drinks %}
|
||||
{% if drink.binary_availability %}
|
||||
{% if drink.do_not_count %}
|
||||
<li>
|
||||
<a class="button" href="/order/{{ drink.id }}">
|
||||
<span>{{ drink }}</span>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<div class="column" id="pricePerDrink" data-drink-price="{% localize off %}{{ drink.price }}{% endlocalize %}">{{ drink.price }}</div>
|
||||
</div>
|
||||
|
||||
{% if not drink.binary_availability %}
|
||||
{% if not drink.do_not_count %}
|
||||
<div class="row">
|
||||
<div class="column">{% translate "Available" %}:</div>
|
||||
<div class="column">{{ drink.available }}</div>
|
||||
|
@ -47,7 +47,7 @@
|
|||
<div class="column">
|
||||
<span class="customNumberInput">
|
||||
<button type="button" class="customNumberInput-minus" id="numberOfDrinksBtnA">-</button>
|
||||
{% if drink.binary_availability %}
|
||||
{% if drink.do_not_count %}
|
||||
<input type="number" class="customNumberInputField" name="numberOfDrinks" id="numberOfDrinks"
|
||||
min="1" max="100" value="1">
|
||||
{% else %}
|
||||
|
|
|
@ -126,7 +126,7 @@ def api_order_drink(request):
|
|||
|
||||
drink = Drink.objects.get(pk=drinkID)
|
||||
|
||||
if ((drink.binary_availability and drink.available > 0) or (drink.available >= amount)) and not drink.deleted:
|
||||
if ((drink.do_not_count and drink.available > 0) or (drink.available >= amount)) and not drink.deleted:
|
||||
Order.objects.create(drink=drink, user=user, amount=amount)
|
||||
return HttpResponse("success", status=200)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue