nshafer / django-hashid-field

Django Model Field that uses Hashids to obscure the value
MIT License
370 stars 40 forks source link

field.id doesn't work for templates #78

Closed joshuakoh1 closed 1 year ago

joshuakoh1 commented 1 year ago

Trying to print out the value of both the hashid and the underlying id in a django template.

field > hashid value field.id > empty field.hashid > empty

nshafer commented 1 year ago

I'm unable to duplicate this. You must have something else going on between the Model and the template, such as resolving the field with str(field) or something similar. For example, I just put this in the sandbox code:

{{ author.name }} ({{ author.id.id }}/{{ author.id.hashid }})

and it properly printed out entries such as:

Arthur C Clarke (1/3586d4894bae7)
Frederik Pohl (1000/85e7469824da6)

in the template output.

I would need a test case that duplicates this problem to debug. At least I need to know exactly what settings are enabled for the field, and see some code in the view where it fetches the records and passes them to the context of the template.