I'm currently trying to make a calculator for a video game. I want the user to be able to select characters from the video game, then the webpage calculates stats about the selected character. So far, all I have is a page that displays a list of names of every character in the database so far. I want a user to be able to select a character from the list, then the program grabs data about that character from the database, and does some calculations on it.
I have a solid enough grasp on models.py, and I have pretty much everything I want in there currently working. I'm I have no idea what direction to head in next. My guess is to edit both views and my html files. This is what my views currently looks like. The characters are named units, and think of class like a job class characters can take on if you're familiar with games.
from django import forms
from .models import Unit
from .models import Class
# Create your views here.
def index(request):
unit_list = Unit.objects.order_by("unit_name")
context = {'unit_list': unit_list}
return render(request, 'calc/index.html', context)
def unit(request, unit_id):
try:
unit = Unit.objects.get(pk=unit_id)
except Unit.DoesNotExist:
raise Http404("Unit does not exist")
return render(request, 'calc/unit.html', {'unit': unit})
#does calculations based on the selected character
def calcStats(currentUnit, currentClass):
hp = max(currentClass.hp_class_base, currentUnit.hp_base + currentClass.hp_class_mod + ((currentUnit.hp_growth * currentUnit.unit_level)/10.0) + ((currentClass.hp_class_growth * currentClass.class_level)/10.0))
hp = min(hp, currentUnit.hp_cap)
stats = [hp]
#grabs the character and other info from the database
class unitSelect(forms.Form):
currentUnit = forms.ChoiceField(label="unit", choices=[(unit.id, unit.unit_name) for unit in Unit.objects.all()])
currentClass = forms.ChoiceField(label="Class", choices=[(Class.id, Class.class_name) for Class in Class.objects.all()])
{% if unit_list %}
<ul>
{% for unit in unit_list %}
<li>{{ unit.unit_name }}</li>
{% endfor %}
</ul>
{% else %}
<p>No units are available.</p>
{% endif %}
Am I on the right track? And what else should I be adding, and what should I be doing next? I tried looking at django tutorials, and I've actually taken some web dev classes in high school and college, but I still feel like I learn nothing every single time. Are there any good resources you recommend? Sorry if it feels like I'm asking too many questions.