On Tue, Oct 27, 2020 at 12:06 AM Adam Fletcher <a...@bit.io> wrote: > Hi Folks, > > I have a custom user model that has a property called 'name' that returns > the username. > > I want to use this property in a ModelSerializer like so: > > owner = serializers.HyperlinkedRelatedField( > read_only=True, > lookup_field="name", > lookup_url_kwarg="username", > view_name="user-detail", > ) > > However, this fails and says my custom user model has no attribute "name". > Any ideas on how to use a property as a lookup field? >
https://www.django-rest-framework.org/api-guide/relations/#hyperlinkedrelatedfield lookup_field - The field on the target that should be used for the lookup. Should correspond to a URL keyword argument on the referenced view. Default is 'pk'. > Thanks! > > -Adam > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-rest-framework+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/CAEP43uNZSoE84Yz6yY-uxAAMz3JRkpAnTquQuHw9L1ajOELRUg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAEP43uNZSoE84Yz6yY-uxAAMz3JRkpAnTquQuHw9L1ajOELRUg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CA%2BFDnhJPkeGRgX6xiP%2Bp_4a6jKhqEfh00sURm%2B-nNcP4ESt%3DjA%40mail.gmail.com.