Closed ElectricFrogy closed 1 year ago
Using this query verified that place id 109331 has a description:
select pd.* from place_description pd join places p on pd.place_id = p.id join datasets D on p.dataset = D."label" where D.id = 257 and pd.place_id = 109331;
On screen no description is shown:
URL is review
backend code is in views.py
method review
ok, problem is centered around the fact that the matches are displayed by reading the results from a json in the hits table which does not contain the description as this is not returned from the matching service. We need to modify the HitFormSet constructor. Here are the instructions:
We need to modify HitModelForm to include additional logic that fetches the PlaceDescription for the relevant IDs in its json field. We'll add a custom property to the form named descriptions to hold this data.
class HitModelForm(forms.ModelForm):
class Meta:
model = Hit
fields = [...] # the fields you've defined previously
def __init__(self, *args, **kwargs):
super(HitModelForm, self).__init__(*args, **kwargs)
# Initialize descriptions to an empty list by default
self.descriptions = []
# Extract relevant IDs from the json field (adjust extraction logic as per your data structure)
if self.instance and self.instance.json:
relevant_ids = self.instance.json.get('relevant_key', []) # replace 'relevant_key' with the actual key
# Fetch PlaceDescription entries for the extracted IDs
self.descriptions = PlaceDescription.objects.filter(id__in=relevant_ids)
Now, in the template, you can access form.descriptions for each form in the formset. Adjust your template logic accordingly:
{% for form in formset %}
{% for desc in form.descriptions %}
<p>{{ desc.jsonb.value }}</p> {# or however your PlaceDescription model's field is structured #}
{% endfor %}
{% endfor %}
The way you create and pass the formset to the template doesn't need to change. Your existing logic should work:
HitFormset = modelformset_factory(
Hit,
fields=('id', 'authority', 'authrecord_id', 'query_pass', 'score', 'json', 'relation_type', 'explanations'),
form=HitModelForm, extra=0)
formset = HitFormset(request.POST or None, queryset=raw_hits)
context['formset'] = formset
This way, each form in the HitFormset will have access to its associated PlaceDescription records via the descriptions property. You can then display them in your template as needed.
Fixed:
When trying to match between locations from two different datasets (Yaqut and Benjamin of Tudela), the descriptions for locations of the latter dataset are not showing. the Dataset of benjamin of Tudela was undoubtably uploaded with a description column. However, they are not showing. here as an image of the described issue:
On the right hand side, descriptions for locations are missing.
Here is a link to the Benjamin of Tudela Dataset