I know that this error is not unique to me. I have come across many posts asking what the error is and how to fix it. One of the answers I saw was to use hasattr
on the returned objects in a for loop before you try to get the attribute of the object. The problem is, is that I actually want to count()
on the QuerySet. I saw some other post use some Django model aggregate function inside of the query, but I don’t think that is appropriate or necessary here. The query should be literally as easy as:
font_count = Fonts.objects.filter(origin=location, font_name=font_name).count()
but it says:
my_app.models.Fonts.origin.RelatedObjectDoesNotExist: Fonts has no origin.
Seems straight forward enough – I’ll just open the interactive django shell and make sure that I can’t get the origin of the Fonts already loaded into the DB… Well, what do you know?! I can access every origin
of every font
that I have loaded! What is this garbage?!
I am on Django version “4.1.dev20211216191317” and python 3.9. origin
is a foreign key and font_name
is a text field.
Thank you 🙂