mik3y / django-spicy-id

🌶️ Cool "Stripe-style" self-identifying row IDs for Django. A drop-in replacement AutoField.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django-polymorphic + OneToOneField does not map to parent field in Admin

VaZark opened this issue · comments

When applying Spicy field to a Django polymorphic model, django throws an error when generating routes with the admin. Admin throws the following errors

#urls.py
register_converter(get_url_converter(ParentModel, 'id'), 'id')
register_converter(get_url_converter(ChildModel, 'id'), 'id')

# error message
 is not valid: value does not match expected regex '^(demande_)([123456789abcdef][0123456789abcdef]{,15})$'

>  self.model.objects.non_polymorphic().values("polymorphic_ctype").get(pk=object_id)
#urls.py
register_converter(get_url_converter(ParentModel, 'id'), 'id')
register_converter(get_url_converter(ChildModel, 'pk'), 'id')

# error message
django.core.exceptions.FieldDoesNotExist: ChildModel has no field named 'pk'

Turns out I had a custom __str__ implementation that was the source of the problem. A little note to remove existing __str__ function would be useful

Removing __str__ worked for the child but the parent does continue to have this error (probably due to pk being used instead of id)

So this could be considered a feature request ticket for adding support for pk :)

Hi @VaZark - hmm, I'm not familiar with django-polymorphic, not sure I understand where a bug could be on our side.

Models using django-spicy-id can be used/queried with pk just like id; nothing special we're doing there. You can see examples of this in tests/fields_test.py.

If you can pinpoint a more specific bug on our side, I'm definitely happy to get it fixed.