Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Alan Crosswell
Yes, I believe the default search keyword is `search`. It searches for a keyword match across all the `search_fields`. I believe that's what you indicated. If you want to search individual fields with a variety of possible relationships, take a look at `DjangoFilterBackend`. On Tue, Oct 30, 2018

Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Asad Habib
Alan, thanks. With this approach do I have to explicitly define URLs in urls.py or are these generated? For the above, would the URL look like the following? localhost/api/units?search=string Where string is the literal string to be searched? If this is the case, how does it know whether I want

Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Alan Crosswell
Asad: I believe what you want should work with SearchFilter. Something like this: from rest_framework.filters import SearchFilter class UnitViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = UnitSerializer queryset = Unit.objects.all() filter_backends = (SearchFilter, )

Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Asad Habib
Alan, appreciate your input. Basically, I want to be able to retrieve units based on either a primary key or other attribute. Is this possible using filtering if URLs are being defined using routers? On Tue, Oct 30, 2018 at 8:23 AM Alan Crosswell wrote: > This seems like you are reinventing Sear

Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Foobar
Thanks Jason. Now, the get_object function in class MultipleFieldLookupMixin is actually being called but it's throwing an error as follows: if self.kwargs[field]: # Ignore empty fields. KeyError: 'unit_name' The ViewSet is defined as follows: class UnitViewSet(CountModelMixin, MultipleFieldLo

Re: Basic understanding / custom field - point of access

2018-10-30 Thread Xavier Ordoquy
Hi, It’s a bit more complex than that. Content négociation along with renderers and parsers will move the data from the HTTP body into basic python types (int / floats / strings). Serializers will move those basic types from and to more complex ones (DateTimes, Decimals, Django models / queryse

Basic understanding / custom field - point of access

2018-10-30 Thread 'enricoba' via Django REST framework
Hi, I am fairly new to Django REST framework, but mid experienced with native Django. First I have a basic question regarding serializers (see picture - using the REST framework tutorial info). For my understanding the serializer transforms a Django queryset into a „readable“ JSON. Therefo

Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Alan Crosswell
This seems like you are reinventing SearchFilter. Maybe I’m misunderstanding. https://www.django-rest-framework.org/api-guide/filtering/ On Mon, Oct 29, 2018 at 2:50 PM Foobar wrote: > I have the following code which doesn't work: > > In models.py: > > class Unit(models.Model): >unit_name =

Re: Custom Mixin for Mulitple Field Object Lookup in Django REST

2018-10-30 Thread Jason
Due to python's method resolution order, you need to have mixins first in the class inheritance order. Specifically class UnitViewSet(MultipleFieldLookupMixin, viewsets.ReadOnlyModelViewset): ... See https://stackoverflow.com/questions/1848474/method-resolution-order-mro-in-new-style-class

Re: apidoc: Slashes in prefix being transformed to > by schema_links template tag;

2018-10-30 Thread Doug Scoular
Hi Daniel, On Tue, 30 Oct 2018 at 09:28, Daniel Cannon wrote: > Did you ever happen to find a solution for this? I'm encountering the same > problem. > I'm afraid not. I'm quite surprised that I never got any response. I have to say that I love the *rest_framework.documentation* module and its