Answer the question
In order to leave comments, you need to log in
How to make feedback for OneToMany in templates in Django?
I ran into a wall, I've been suffering for 2 days, help me out!
There are 2 models:
class Universe(models.Model):
name = models.CharField(max_length=50, unique=True)
lore = models.TextField(max_length=200)
class Achievement(models.Model):
uni = models.ForeignKey( Universe)
name = models.CharField(max_length=50)
There is a view in views.py:
class UniverseDetailView(DetailView):
model = Universe
and a template for it universe_detail.html
{% block content %}
Universe: {{ universe.name }}
History: {{ universe.lore }}
Achievements:
{% endblock %}
How can I get a list of achievements from this universe? Something like
{% for Achievement in universe.Achievement.all %} For the ManyToMany connection, this is exactly how it worked for me ...
Maybe I need to create a separate form for this? Or add a function to the Universe model?
Answer the question
In order to leave comments, you need to log in
jsfiddle.net/wf6hkpr0
if the line contains only the description of the function (without the body, as in the example), then you can https://regex101.com/r/iA6pL8/1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question