Re: URL wih dot in Django Rest Framework

2017-01-11 Thread Xavier Ordoquy
This is similar to issue #4341

Regards,
Xavier Ordoquy,
Linovia.

> Le 11 janv. 2017 à 00:58, Bernardo Garcia  a écrit :
> 
> I have the following model with a primary_key=True specified: 
> 
> class Team(models.Model):
> name = models.CharField(
> max_length=64,
> primary_key=True,
> )
> ... other fields
> 
> When I serialize this model, I do the following:
> 
> class TeamSerializer(serializers.ModelSerializer):
>class Meta:
> model = Team
> fields = ('url', 'name',) # and another fields
> 
> 
> My viewset:
> 
> class TeamViewSet(viewsets.ModelViewSet):
> lookup_value_regex = '[-\w.]'
> queryset = Team.objects.all()
> serializer_class = TeamSerializer
> filter_fields = ('name',) # and another fields
> 
> My urls.py:
> 
> router = routers.DefaultRouter()
> router.register(r'teams', TeamViewSet)
> 
> urlpatterns = [
> url(r'^api/', include(router.urls)),
> 
> # I am not sure if this url is right. I repeat of include(router.urls)
> url(r'^api/teams/(?P[-\w.]+)/', include(router.urls)),
> 
> url(r'^api-auth/', include('rest_framework.urls', 
> namespace='rest_framework'))
> ]
> 
> Then, when I create a Team object with name attribute containing dot ., for 
> example Latinos F.C. and I go to the rest url, I get:
> 
>  
> 
> 
> I am not sure about of how to use the lookup_value_regex attribute in my 
> viewset. In this answer  is used 
> with some basic regex, but if I use it, any Team object is reachable via my 
> serialized Rest API.
> 
> How to can I get a url like as: /api/teams/Name.F.C. in my serialized Team 
> model?
> 
> 
> -- 
> 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 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


URL wih dot in Django Rest Framework

2017-01-10 Thread Bernardo Garcia
I have the following model with a primary_key=True specified: 

class Team(models.Model):
name = models.CharField(
max_length=64,
primary_key=True,
)
... other fields


When I serialize this model, I do the following:

class TeamSerializer(serializers.ModelSerializer):
   class Meta:
model = Team
fields = ('url', 'name',) # and another fields



My viewset:

class TeamViewSet(viewsets.ModelViewSet):
lookup_value_regex = '[-\w.]'
queryset = Team.objects.all()
serializer_class = TeamSerializer
filter_fields = ('name',) # and another fields


My urls.py:

router = routers.DefaultRouter()
router.register(r'teams', TeamViewSet)

urlpatterns = [
url(r'^api/', include(router.urls)),

*# I am not sure if this url is right. I repeat of include(router.urls)*
url(r'^api/teams/(?P[-\w.]+)/', include(router.urls)),

url(r'^api-auth/', include('rest_framework.urls', 
namespace='rest_framework'))
]


Then, when I create a Team object with name attribute containing dot ., for 
example *Latinos F.C.* and I go to the rest url, I get:




I am not sure about of how to use the lookup_value_regex attribute in my 
viewset. In this answer  is 
used with some basic regex, but if I use it, any Team object is reachable 
via my serialized Rest API.

How to can I get a url like as: /api/teams/Name.F.C. in my serialized Team
 model?

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