1. Make a form for updating the reorder level
class ReorderLevelForm(forms.ModelForm):
class Meta:
model = Stock
fields = ['reorder_level']
2. Make a view for reorder level
def reorder_level(request, pk):
queryset = Stock.objects.get(id=pk)
form = ReorderLevelForm(request.POST or None, instance=queryset)
if form.is_valid():
instance = form.save(commit=False)
instance.save()
messages.success(request, "Reorder level for " + str(instance.item_name) + " is updated to " + str(instance.reorder_level))
return redirect("/list_items")
context = {
"instance": queryset,
"form": form,
}
return render(request, "add_items.html", context)
3. Make a url for editing the reorder level
path('reorder_level/<str:pk>/', views.reorder_level, name="reorder_level"),
4. Make a template tag condition with a div rapping the quantity field that will apply a style to the field when the reorder level is equal to or less than the quantity
<td>
{% if instance.quantity <= instance.reorder_level %}
<div style="background-color: orange;">{{instance.quantity}}</div>
{% else %}{{instance.quantity}}
{% endif %}
</td>
5. Add a column for reorder level and make is clickable to update the reorder level
<td><a href="{% url 'reorder_level' instance.id %}">{{instance.reorder_level}}</a></td>
Excellent teaching. You deserve an oscar
Thank you Evans
What if issue quantity is greater than the stock. I am getting negative stock
I guess I solved that using the if statement. Check the codes
How would we go about, if lets say I want to have 2 colors one orange with stock level is at a certain amount but once stock reaches 10 or less for it to turn red?
Would you be so kind as to help me with that?
You can use several if statements
Hello Arbadjie, after I was migrated datebase from sqlite3 to MySQL. my Add Item Page for field category can’t use at reuse category in the same id, although mycode in class model category attribute using ‘blank=True’. could you give me suggestion how to add item in the same category in MySQL environment database? cause I look your video above showing that the items is already added in the same category.