Lookup Field - Values with dots in them.

363 views
Skip to first unread message

David Markey

unread,
Dec 15, 2014, 10:12:16 AM12/15/14
to django-res...@googlegroups.com
Hi there,

I have a lookup field that has values that have dots in them. It seems like the auto url generation prohibits dots in the lookup values(and therefore reverse breaks)

Any ideas on how to work around it?

David


Tom Christie

unread,
Dec 15, 2014, 11:50:45 AM12/15/14
to django-res...@googlegroups.com
I think you're going to have to break this down with an example.

David Markey

unread,
Dec 15, 2014, 12:00:07 PM12/15/14
to django-res...@googlegroups.com
Ok, so I've registered a ReadOnlyModelViewSet with a PK called "version" that's a CharField, and on this particular object this is set to "7.6"

So the resultant URL for the detail view is ProductVersion/(?P<version>[^/.]+)/$ [name='productversion-detail']

So, when I go to ProductVersion/7.6/ it gives the standard Django 404, however if I go to ProductVersion/7_6/ it returns a 
{
    "detail": "Not found"
}

Which is expected, which tells me the dot in the URL is the problem,

David

--
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-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Christie

unread,
Dec 15, 2014, 12:37:11 PM12/15/14
to django-res...@googlegroups.com, ad...@dmarkey.com
Yup, the '.' character can conflict with the suffix [.json] type lookups, so are excluded by default.
You can set `lookup_value_regex` directly to work around this...

David Markey

unread,
Dec 15, 2014, 3:45:42 PM12/15/14
to Tom Christie, django-res...@googlegroups.com
Thank a lot. Will try it tomorrow.

Loke Berne

unread,
Mar 16, 2016, 7:46:13 AM3/16/16
to Django REST framework, christ...@gmail.com, ad...@dmarkey.com
I am having exactly the same problem in my case I have the following setting 

   lookup_field = 'hostname'
   lookup_value_regex = '[0-9a-z\.]+'

But I am still getting the error and the following regexp as accepted 

^device\.(?P<format>[a-z0-9]+)/?$ [name='device-list']
^device/(?P<hostname>[0-9a-z.]+)/$ [name='device-detail']
^device/(?P<hostname>[0-9a-z.]+)\.(?P<format>[a-z0-9]+)/?$ [name='device-detail']

Note that the bold part still does not use the regexp specified
Reply all
Reply to author
Forward
0 new messages