Closed susanodd closed 2 months ago
There might need to be a migration to make the ForeignKey be an object and not just an ID ?
(We had this problem with handshapes at the start because they started out as a machine value and needed to become an object. @vanlummelhuizen is an expert in this. Maybe he can take a look.)
I'm not sure that is the problem because the function does work in other places, and gloss is linked to as ForeignKey
See in AnnotatedGloss model:
gloss = models.ForeignKey("Gloss", on_delete=models.CASCADE)
What do you want to retrieve?
Maybe try
print(this.gloss.annotationidglosstranslation_set.all())
to check what that does. Maybe the filter in show_annotationidglosstranslation is too strict.
I'm not sure that is the problem because the function does work in other places, and gloss is linked to as ForeignKey See in AnnotatedGloss model:
gloss = models.ForeignKey("Gloss", on_delete=models.CASCADE)
What do you want to retrieve?
Maybe try
print(this.gloss.annotationidglosstranslation_set.all())
to check what that does. Maybe the filter in show_annotationidglosstranslation is too strict.
No, I'm not trying to retrieve the things I printed. I was trying to debug the code. I only wanted to get the Gloss out of the AnnotatedGloss.
this = AnnotatedGloss.objects.get(id=annotatedgloss_id)
this_gloss = Gloss.objects.get(id=this.gloss_id)
It doesn't work to do this.gloss
for example. It's not a Gloss object.
I had to write the second line to retrieve an object.
I suspect it's to do with whether it's joining tables or trying to get an object. It can do fine if it's joining tables, but it can't get the object.
I added a pre_fetch but that didn't solve the above problem.
Here is an example screenshot with the Sentence ID in the list view. To me it looks like variations on the same sentence, like the end of the sentence is cropped in some, so it looks like there are some objects that ere edited but the old ones not removed? (Sentence ID 21, 22.)
Here is the screenshot of AnnotatedGloss list, with the column containing the Annotated Sentence.
Btw, very cool! I had no idea there were so many sentences!
Just a guess thinking about this, it may have something to do with how data is created. Whether the constructor is used, or whether the create_or_get is used. The constructor creates an object, the create_or_get inserts into the table. (Need to ask @vanlummelhuizen about this.)
This has been programed away in various places.
[THIS ISSUE IS ABOUT CODE]
It seems the data stored in the model
AnnotatedGloss
, the field stored in "gloss
" is actually an ID, not a foreign key. So an additional lookup is needed to retrieve theGloss
object using this ID. (Normally, if you retrieve the value in a foreign key field it should be an object.)This method doesn't work:
https://github.com/Signbank/Global-signbank/blob/afaa5ce1006d80e60aee8580606469ee8edd8f50/signbank/dictionary/models.py#L3956-L3957
Inside my loop, I have both the annotated gloss (variable
this
) and the gloss object (this_gloss
), and the following:where "this" is an annotated gloss and "this_gloss" is the gloss. The second print does not output anything, but the first and third do.
Originally posted by @susanodd in https://github.com/Signbank/Global-signbank/issues/1305#issuecomment-2277504193