Hi !
But I saw in the groups that if you don't use the ORM part and, just like
me, you need only the front part, you cannot use views such as APIView
because it seems to be hardly linked to the Models. Because I use my own
models that does not inheritate from django models), the APIView cannot
handle this.
And for the record, because I dont have too much time, I did not implement
tests so hard to see where in args or kwargs the id is located, even when I
analyzed the django request library
So I implement my own view:
@api_view(["GET", "POST"])
def ProductDetail(aRequest, pk):
"""
@brief Retrieve a products or create a new product.
"""
if aRequest.method == 'GET':
print("GET METHOD")
print(pk)
elif aRequest.method == 'POST':
print("POST METHOD")
try:
# JSON data retrieval
wData = aRequest.data
# Serializer instanciation
wSerializer = ProductSerializer()
# Validation checkings: @TODO
# Product creation
wCreatedProductDict = wSerializer.Create(aData=wData)
# response return
print("VIEWS: wCreatedproduct")
print(wCreatedProductDict)
return Response(wCreatedProductDict, status=status.HTTP_201_CREATED)
except Exception:
traceback.print_exc()
return Response(status=status.HTTP_400_BAD_REQUEST)
Now it works much better, but indeed I have to write my own serializer.
BUT ! I there is a trick to retreive the Id defined in the path in an
APIView, do not hesitate to tell me :)
King regards,
Benjamin.
Le mardi 14 août 2018 14:03:27 UTC+2, g a écrit :
>
> Good morning Benjamin. This is a Django problem. You should read the
> Django getting started tutorial. But your url params are available in the
> views. Try adding *args and **kwargs in the get a post method definition.
> On my cell so can't give direct links
>
> On Tue, Aug 14, 2018, 7:51 AM Benjamin SOULAS <[email protected]
> <javascript:>> wrote:
>
>> To be more precise, I Don't need the ORM part (including Models) but only
>> the front which handle data received, Maybe the APIView I use does not work
>> If no Models has been used? Which could explain that I cannot retreive the
>> ID of the path which should be linked to the Models (in which I should have
>> defined the given ID?)
>>
>> I really need answers ....
>>
>> Kind Regards
>>
>> --
>> 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 [email protected] <javascript:>
>> .
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.