Closed bluesurfer closed 4 months ago
Yup, that one's on me. Fixed in #17, just needs a review/merge/release by @andrewgodwin.
@rixx I tried exactly that fix. But I got a different attribute error in the to_representation method. This is what worked for me:
class UrlManField(DictField):
"""Serializer class for Django Restframework."""
def __init__(self, urls, attribute="urls", full=True, *args, **kwargs):
# Temporary fix for https://github.com/andrewgodwin/urlman/issues/16
super().__init__(
*args,
read_only=True,
write_only=False,
label=None,
source='*',
**kwargs
)
self.urls = urls
self.url_attribute = attribute
self.full = full
Hmm, I just merged #17 but if it's not what works we need to change it - what was the exact error you got with that new code?
But I got a different attribute error in the to_representation method.
Oh, that would have been good to know beforehand. I tried to test it with the project I use urlman in, but it next failed for me with a problem unrelated to urlman (I use partials in a serializer and it fails to deal with that), so I didn't look into it further, as the reported bug went away.
Out of curiosity, I fixed the problem, and can't reproduce the error (though the schema shows the URL field to be a string). I'll open a PR with a variation of your solution.
@rixx @andrewgodwin if you apply the fix of #17 then url_class
becomes a dictionary (don't know why). You should therefore get AttributeError: 'dict' object has no attribute 'view'
where view
is a url listed in urls
.
When using
UrlManField
withdrf-spectacular
I getAttributeError: 'UrlManField' object has no attribute 'allow_null'
when visiting the docs.