So as soon as I get it working my colleques want changes.
Question:
Is there a way to get one set of values from a query set into a css style sheet?
my model has 2 attributes - area - the name of the area and area text - its description
I want to use area within 8 shapes in a flexbox, but when I try to format the css I either get both attributes or an empty shape, i.e.:
The relevant code is:
class Area(models.Model):
area = models.CharField(max_length=30)
areatext = models.CharField(max_length=400)
def __str__(self):
return f"{self.area} Purpose: {self.areatext}"
HTML:
<div class="space"></div>
<div class="item_context">{{ area.area.0 }}</div>
<div class="space"></div>
<div class="item_leadership">{{ area.1 }}</div>
<div class="space"></div>
It works fine elsewhere, but within a for loop that gets the relevant values and I donât think a for loop would work.
Is there another way to extract the equivalent of a_area, without a for loop, so I could use a_area.area?
<tr>{% for a_area in area %}</tr>
<td colspan="7">
<div>{{ a_area.area }}</div>
<p></p>
<div>{{ a_area.areatext}}</div>
I want to avoid having to create a separate list of Areas just for the header.
I also tried prefetching areaheader from a different model but got:
AttributeError: Cannot find âareaheader_setâ on Area object, âareaheader_setâ is an invalid parameter to prefetch_related()
class Area_Header(models.Model):
areaheader = models.CharField(max_length=400)
area = models.ForeignKey(
Area, on_delete=models.CASCADE, null = True
)
in views.py:
areas = Area.objects.all().prefetch_related('question_set', 'areaheader_set')
If I use:
areas = Area.objects.all().prefetch_related('question_set', 'area_header_set')
No error but still not text in shape if I use:
<div class="item_context">{{ area.areaheader.0 }}</div>