Re: Django Rest Framework support for Django 4.2
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST ='smtp.gmail.com' EMAIL_USE_TLS=True EMAIL_PORT=587 EMAIL_HOST_USER=<"my_gmail"> EMAIL_HOST_PASSWORD=<"app_password"> smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. For more information, go to\n5.7.0 https://support.google.com/mail/?p=WantAuthError q36-20020a635c2400b005ce979b861dsm4765154pgb.84 - gsmtp', ' smtp.gmail.com') Can someone help me with this? I'm getting this error On Thu, 6 Jul, 2023, 9:01 pm Alex Clough, wrote: > Thanks, Carlos! > > On Thursday, July 6, 2023 at 11:06:26 AM UTC-4 croch...@gmail.com wrote: > >> i think yes! >> >> On Thu, Jul 6, 2023 at 9:03 AM Alex Clough >> wrote: >> >>> Hello Carlos, >>> >>> So, just to clarify, if I am pinning Django 4.2.3 (latest release) and >>> DRF 3.14.0 (latest release) in a requirements file, I will be good to go? >>> >>> Thank you in advance. >>> >>> Alex >>> >>> On Friday, May 26, 2023 at 11:45:30 AM UTC-4 croch...@gmail.com wrote: >>> >>>> Hi, if you need install the master/main branch you try this >>>> pip install >>>> https://github.com/encode/django-rest-framework/archive/refs/heads/master.zip >>>> if you do not want to wait for the tag 3.15 >>>> >>>> cheers >>>> >>>> On Fri, May 26, 2023 at 9:33 AM Vitan Ivanov >>>> wrote: >>>> >>>>> Hey Carlos, thanks for the fast reply! >>>>> Master supports it, but the latest tagged version is 3.14 and it >>>>> doesn't. So my question is when we can expect a new tag (3.15 maybe?) >>>>> >>>>> On Fri, May 26, 2023, 18:25 carlos wrote: >>>>> >>>>>> Hi, i think DRF now support D4.2 >>>>>> https://github.com/encode/django-rest-framework#requirements >>>>>> >>>>>> Cheers >>>>>> >>>>>> On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov >>>>>> wrote: >>>>>> >>>>>>> Hello group! >>>>>>> >>>>>>> Django 4.2 is listed as an LTS version in the release notes >>>>>>> <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems >>>>>>> like it's the most appropriate version to start projects or upgrade to. >>>>>>> >>>>>>> Does anybody know when the new version of DRF which would support >>>>>>> Django 4.2 is expected? >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>>> To view this discussion on the web visit >>>>>>> https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com >>>>>>> <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>>> . >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> att. >>>>>> Carlos Rocha >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to a topic in >>>>>> the Google Groups "Django REST framework" group. >>>>>> To unsubscribe from this topic, visit >>>>>> https://groups.google.com/d/topic/django-rest-framework/j-TkbRyiQ1o/unsubscribe >>>>>> . >>>>>> To unsubscribe from this group and all its topics, send an email to >>>>>> django-rest-fram...@googlegroups.com. >>>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com >>>>>> <https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> -
How to upload a folder in Django Rest Framework, or a zip file
Hi guys, I want to upload a folder or a zip file then exracting its content, and save everything in the database. I'm using Djanogo Rest Framework -- 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/95e0e660-be60-47a4-97f3-f2169fafe260n%40googlegroups.com.
Re: Django Rest Framework support for Django 4.2
Thanks, Carlos! On Thursday, July 6, 2023 at 11:06:26 AM UTC-4 croch...@gmail.com wrote: > i think yes! > > On Thu, Jul 6, 2023 at 9:03 AM Alex Clough > wrote: > >> Hello Carlos, >> >> So, just to clarify, if I am pinning Django 4.2.3 (latest release) and >> DRF 3.14.0 (latest release) in a requirements file, I will be good to go? >> >> Thank you in advance. >> >> Alex >> >> On Friday, May 26, 2023 at 11:45:30 AM UTC-4 croch...@gmail.com wrote: >> >>> Hi, if you need install the master/main branch you try this >>> pip install >>> https://github.com/encode/django-rest-framework/archive/refs/heads/master.zip >>> if you do not want to wait for the tag 3.15 >>> >>> cheers >>> >>> On Fri, May 26, 2023 at 9:33 AM Vitan Ivanov >>> wrote: >>> >>>> Hey Carlos, thanks for the fast reply! >>>> Master supports it, but the latest tagged version is 3.14 and it >>>> doesn't. So my question is when we can expect a new tag (3.15 maybe?) >>>> >>>> On Fri, May 26, 2023, 18:25 carlos wrote: >>>> >>>>> Hi, i think DRF now support D4.2 >>>>> https://github.com/encode/django-rest-framework#requirements >>>>> >>>>> Cheers >>>>> >>>>> On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov >>>>> wrote: >>>>> >>>>>> Hello group! >>>>>> >>>>>> Django 4.2 is listed as an LTS version in the release notes >>>>>> <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems >>>>>> like it's the most appropriate version to start projects or upgrade to. >>>>>> >>>>>> Does anybody know when the new version of DRF which would support >>>>>> Django 4.2 is expected? >>>>>> >>>>>> -- >>>>>> 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. >>>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com >>>>>> >>>>>> <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> >>>>> >>>>> -- >>>>> att. >>>>> Carlos Rocha >>>>> >>>>> -- >>>>> You received this message because you are subscribed to a topic in the >>>>> Google Groups "Django REST framework" group. >>>>> To unsubscribe from this topic, visit >>>>> https://groups.google.com/d/topic/django-rest-framework/j-TkbRyiQ1o/unsubscribe >>>>> . >>>>> To unsubscribe from this group and all its topics, send an email to >>>>> django-rest-fram...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com >>>>> >>>>> <https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%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-fram...@googlegroups.com. >>>> >>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com >>>> >>>> <https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> att. >>> Carlos Rocha >>> >> -- >> 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. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-rest-framework/99d523ce-88cb-4ff6-ba4d-f746a8d8f620n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-rest-framework/99d523ce-88cb-4ff6-ba4d-f746a8d8f620n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > att. > Carlos Rocha > -- 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/a0720e48-f81f-4c10-832b-d532385ce006n%40googlegroups.com.
Re: Django Rest Framework support for Django 4.2
i think yes! On Thu, Jul 6, 2023 at 9:03 AM Alex Clough wrote: > Hello Carlos, > > So, just to clarify, if I am pinning Django 4.2.3 (latest release) and DRF > 3.14.0 (latest release) in a requirements file, I will be good to go? > > Thank you in advance. > > Alex > > On Friday, May 26, 2023 at 11:45:30 AM UTC-4 croch...@gmail.com wrote: > >> Hi, if you need install the master/main branch you try this >> pip install >> https://github.com/encode/django-rest-framework/archive/refs/heads/master.zip >> if you do not want to wait for the tag 3.15 >> >> cheers >> >> On Fri, May 26, 2023 at 9:33 AM Vitan Ivanov >> wrote: >> >>> Hey Carlos, thanks for the fast reply! >>> Master supports it, but the latest tagged version is 3.14 and it >>> doesn't. So my question is when we can expect a new tag (3.15 maybe?) >>> >>> On Fri, May 26, 2023, 18:25 carlos wrote: >>> >>>> Hi, i think DRF now support D4.2 >>>> https://github.com/encode/django-rest-framework#requirements >>>> >>>> Cheers >>>> >>>> On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov >>>> wrote: >>>> >>>>> Hello group! >>>>> >>>>> Django 4.2 is listed as an LTS version in the release notes >>>>> <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems >>>>> like it's the most appropriate version to start projects or upgrade to. >>>>> >>>>> Does anybody know when the new version of DRF which would support >>>>> Django 4.2 is expected? >>>>> >>>>> -- >>>>> 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. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> >>>> >>>> -- >>>> att. >>>> Carlos Rocha >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Django REST framework" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/django-rest-framework/j-TkbRyiQ1o/unsubscribe >>>> . >>>> To unsubscribe from this group and all its topics, send an email to >>>> django-rest-fram...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com >>>> <https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%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-fram...@googlegroups.com. >>> >> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> att. >> Carlos Rocha >> > -- > 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/99d523ce-88cb-4ff6-ba4d-f746a8d8f620n%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/99d523ce-88cb-4ff6-ba4d-f746a8d8f620n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- att. Carlos Rocha -- 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/CAM-7rO31jo3qj8uyx%3Dxu1U1MOtAFD63G9M3zQgaqBKuCZ8Ljfw%40mail.gmail.com.
Re: Django Rest Framework support for Django 4.2
Hello Carlos, So, just to clarify, if I am pinning Django 4.2.3 (latest release) and DRF 3.14.0 (latest release) in a requirements file, I will be good to go? Thank you in advance. Alex On Friday, May 26, 2023 at 11:45:30 AM UTC-4 croch...@gmail.com wrote: > Hi, if you need install the master/main branch you try this > pip install > https://github.com/encode/django-rest-framework/archive/refs/heads/master.zip > if you do not want to wait for the tag 3.15 > > cheers > > On Fri, May 26, 2023 at 9:33 AM Vitan Ivanov wrote: > >> Hey Carlos, thanks for the fast reply! >> Master supports it, but the latest tagged version is 3.14 and it doesn't. >> So my question is when we can expect a new tag (3.15 maybe?) >> >> On Fri, May 26, 2023, 18:25 carlos wrote: >> >>> Hi, i think DRF now support D4.2 >>> https://github.com/encode/django-rest-framework#requirements >>> >>> Cheers >>> >>> On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov >>> wrote: >>> >>>> Hello group! >>>> >>>> Django 4.2 is listed as an LTS version in the release notes >>>> <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems like >>>> it's the most appropriate version to start projects or upgrade to. >>>> >>>> Does anybody know when the new version of DRF which would support >>>> Django 4.2 is expected? >>>> >>>> -- >>>> 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. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> att. >>> Carlos Rocha >>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "Django REST framework" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/django-rest-framework/j-TkbRyiQ1o/unsubscribe >>> . >>> To unsubscribe from this group and all its topics, send an email to >>> django-rest-fram...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%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-fram...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > att. > Carlos Rocha > -- 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/99d523ce-88cb-4ff6-ba4d-f746a8d8f620n%40googlegroups.com.
Re: Django Rest Framework support for Django 4.2
Hi, if you need install the master/main branch you try this pip install https://github.com/encode/django-rest-framework/archive/refs/heads/master.zip if you do not want to wait for the tag 3.15 cheers On Fri, May 26, 2023 at 9:33 AM Vitan Ivanov wrote: > Hey Carlos, thanks for the fast reply! > Master supports it, but the latest tagged version is 3.14 and it doesn't. > So my question is when we can expect a new tag (3.15 maybe?) > > On Fri, May 26, 2023, 18:25 carlos wrote: > >> Hi, i think DRF now support D4.2 >> https://github.com/encode/django-rest-framework#requirements >> >> Cheers >> >> On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov >> wrote: >> >>> Hello group! >>> >>> Django 4.2 is listed as an LTS version in the release notes >>> <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems like >>> it's the most appropriate version to start projects or upgrade to. >>> >>> Does anybody know when the new version of DRF which would support Django >>> 4.2 is expected? >>> >>> -- >>> 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/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> att. >> Carlos Rocha >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Django REST framework" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/django-rest-framework/j-TkbRyiQ1o/unsubscribe >> . >> To unsubscribe from this group and all its topics, 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/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%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/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- att. Carlos Rocha -- 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/CAM-7rO1n0N-GwUoMRzGuYOs%2BZK1_TFhcr_VvKnqPHF7DqrMSHg%40mail.gmail.com.
Re: Django Rest Framework support for Django 4.2
Hey Carlos, thanks for the fast reply! Master supports it, but the latest tagged version is 3.14 and it doesn't. So my question is when we can expect a new tag (3.15 maybe?) On Fri, May 26, 2023, 18:25 carlos wrote: > Hi, i think DRF now support D4.2 > https://github.com/encode/django-rest-framework#requirements > > Cheers > > On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov > wrote: > >> Hello group! >> >> Django 4.2 is listed as an LTS version in the release notes >> <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems like >> it's the most appropriate version to start projects or upgrade to. >> >> Does anybody know when the new version of DRF which would support Django >> 4.2 is expected? >> >> -- >> 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/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com >> <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > att. > Carlos Rocha > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django REST framework" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-rest-framework/j-TkbRyiQ1o/unsubscribe > . > To unsubscribe from this group and all its topics, 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/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%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/CAC-YOfbf-utp%2B2o0zc6W0iN0JbySjvgKm9DW4T0QjXjQKpP5Aw%40mail.gmail.com.
Re: Django Rest Framework support for Django 4.2
Hi, i think DRF now support D4.2 https://github.com/encode/django-rest-framework#requirements Cheers On Fri, May 26, 2023 at 5:33 AM Vitan Ivanov wrote: > Hello group! > > Django 4.2 is listed as an LTS version in the release notes > <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems like > it's the most appropriate version to start projects or upgrade to. > > Does anybody know when the new version of DRF which would support Django > 4.2 is expected? > > -- > 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/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- att. Carlos Rocha -- 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/CAM-7rO3ghVbTuvnGu%3DOBH3u8X8tR7Fyo5e3yUrasX%2B_Q-n4%2BnA%40mail.gmail.com.
Django Rest Framework support for Django 4.2
Hello group! Django 4.2 is listed as an LTS version in the release notes <https://docs.djangoproject.com/en/4.2/releases/4.2/> so it seems like it's the most appropriate version to start projects or upgrade to. Does anybody know when the new version of DRF which would support Django 4.2 is expected? -- 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/537f6bd4-91e2-4891-8a7f-51685ef58235n%40googlegroups.com.
Django Rest Framework nested serializer returns empty list
Hello, I have a problem that I stuck on for sometimes now. I have two models with their respective serializers, these models have @property functions. The idea is to create API endpoints from one model special for posting data and another one to get/retrieve data from the other model. I manage to post using this endpoint, but if I want to get from other endpoint, it returns an empty list. I have posted the source code on Stack Overflow as shown in the link below:- https://stackoverflow.com/questions/75868539/django-rest-framework-nested-serializer-returns-empty-list Regards, Lodger -- 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/258579b3-81bb-4fb5-97fe-d1449d40585bn%40googlegroups.com.
Dear participants Django REST framework could you take part in our survey please?
We on the way to create new tools for Python developers, and to confirm the functionality we develop, we created this survey. *Django framework survey* <https://forms.gle/zKPja2wBGFktb9xE7> Helpfully your participation that we make useful things for the entire Python community. This survey is addressed primarily to software development, business owners, project managers, DevOps, stakeholders, a party that has an interest in a company and can either affect or be affected by the business. and owners of multiple disparate projects, using the Django framework. Independent and team developers whose projects are implemented in Django. There are no product ads here and the purpose of this survey is only to determine the relevance of the problems that developers most often face. -- 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/db56d815-9c04-4426-ba1d-240f76974df1n%40googlegroups.com.
Django REST FRAMEWORK API
please sent the complete clarification for the DJANGO RESTFRAMEWORK API from scratch -- 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/0f782d1d-c806-4fc4-8f71-e988365cea38n%40googlegroups.com.
OTP verification in Django rest framework
Hi, I completed OTP verification in Django. With html form and django views and I am saving otp in the user model itself. There I was successfully completed. Here is a code snippet. `HTML form` ``` {% csrf_token %} ``` `Views.py` ``` def phone_otp_verify(request, id): Qurycustomer = customer.objects.get(id=id) email = Qurycustomer.email email_split = email.split('@') email_list = email_split[0] email_hide = email_list[:2] + "*" + email_split[1] phone_number = Qurycustomer.phonenumber phone_hide = phone_number[-4:] modified_date = Qurycustomer.modified_date date_now = timezone.now() date_total = date_now - modified_date minutes = date_total.seconds / 60 OTP = Qurycustomer.phone_OTP if minutes < 11: OTP = Qurycustomer.phone_OTP # To get server side IP address. We are using ipware django package. client_ip, is_routable = get_client_ip(request) ip_address = client_ip # here we took one variable as osname and concatenated os name and version osname = request.user_agent.os.family + " " + request.user_agent.os.version_string webname = request.user_agent.browser.family + " " + request.user_agent.browser.version_string if request.method == 'POST': security_1 = request.POST['security_1'] security_2 = request.POST['security_2'] security_3 = request.POST['security_3'] security_4 = request.POST['security_4'] security_5 = request.POST['security_5'] # password = request.POST['password'] # repassword = request.POST['repassword'] OTP_entered = str(security_1) + str(security_2) + str(security_3) + str(security_4) + str(security_5) # OTP_entered = str(security_1) + str(security_2) + str(security_3) + str(security_4) OTP_en = int(OTP_entered) if OTP == OTP_en: # Here, encrypting password by using hashers library in django. # enc_password = pbkdf2_sha256.encrypt(password, rounds=12000, salt_size=32) # enc_repassword = pbkdf2_sha256.encrypt(repassword, rounds=12000, salt_size=32) Qurycustomer.cust_status = 1 Qurycustomer.phone_verify = 1 # Qurycustomer.password = enc_password # Qurycustomer.repassword = enc_repassword Qurycustomer.phone_OTP = 0 Qurycustomer.os_name = osname Qurycustomer.browser = webname Qurycustomer.ip_address = ip_address Qurycustomer.history.change_by_reason = "Phone number verified" Qurycustomer.save() # Welcome back! your membership activation is completed. success = "Thank you for registering with Vikreya. Your membership activation is completed. " # success = "Security code has been validated and Phone number verification is completed. You can now " return redirect('/home') else: messages.add_message(request, messages.ERROR, """You enter Security code is not valid. Try once again with correct Security code.""", fail_silently=False) return render(request, 'phone_otp_verify.html', {'id': Qurycustomer.id, 'otp': OTP, 'fullname': fullname(email), 'name': first_last_initial(email), 'time': settings.SESSION_IDLE_TIMEOUT, 'phone_hide': phone_hide}) else: Qurycustomer.phone_OTP = 0 Qurycustomer.save() messages.add_message(request, messages.ERROR, "Sorry the OTP is expired, please click Re-send OTP to generate new OTP.") return render(request, 'phone_otp_verify.html', {'id': Qurycustomer.id, 'otp': OTP, 'fullname': fullname(email), 'name': first_last_initial(email), 'time': settings.SESSION_IDLE_TIMEOUT, 'phone_hide': phone_hide}) return render(request, 'phone_otp_verify.html', {'id': Qurycustomer.id, 'otp': OTP, 'fullname': fu
Django REST Framework PUT request to update an image
I have managed to use the Django REST-framework to upload an image associated with an item. However, the PUT request throws an error (400) when attempting to update the image. Here is the code: - Model: - image = models.ImageField(upload_to="images/", blank=True, null=True) - Serializer: - class ItemSerializer(serializers.ModelSerializer): class Meta: model = Item fields = "__all__" - View: - @api_view(["GET", "PUT"]) def api_item_beta(request, pk): try: item = Item.objects.get(pk=pk) except Item.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == "GET": serializer = ItemSerializer(item) return Response(serializer.data) elif request.method == "PUT": serializer = ItemSerializer(item, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) So, I can POST an image using this serializer. The PUT request works for everything EXCEPT the image. The image data is identical in both cases (where I am posting and putting). What am I missing that the serializer is expecting?? Any help much appreciated! -- 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/0d8c2a9d-b3fc-4bae-b8ab-36120e9775a2n%40googlegroups.com.
What is the proper way to upload files using FileField in Models and Serializers in Django Rest Framework?
I am making a simple DRF Login App which will let the user to upload a CSV file and its description upon registration. It is working fine but when I upload the file, it gives the error The submitted data was not a file. Check the encoding type on the form.. I have searched around the internet but there are questions related to only ImageField (that is image) not FileField. SO I was unable to solve the issue. My *Models.py* is: *class Detail*(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) file = models.FileField(verbose_name="CSV File", upload_to='csv_files') file_desc = models.TextField("CSV File Description") *def __str__*(self): *return *("{} ({} {})".format(self.user.email, self.user.first_name, self.user.last_name)) My *Serializers.py* is: *class MainRegisterSerializer*(serializers.ModelSerializer): *class Meta*: model = User fields = ('username', 'first_name', 'last_name', 'email', 'password') *class RegisterSerializer*(serializers.ModelSerializer): register = MainRegisterSerializer() *class Meta*: model = Detail fields = ['register', 'file', 'file_desc'] optional_fields = ['file', 'file_desc'] extra_kwargs = {'password': {'write_only': True}} *def create*(self, validated_data): user = User.objects.create_user(validated_data['register']['username'], validated_data['register']['email'], validated_data['register']['password']) user.first_name = validated_data['register']['first_name'] user.last_name = validated_data['register']['last_name'] user.save() detail = Detail(user=user, file=validated_data['file'], file_desc=validated_data['file_desc']) detail.save() *return *user My *Views.py* is: *class RegisterAPI*(APIView): renderer_classes = [TemplateHTMLRenderer] template_name = 'accounts/register.html' *def get*(self, request): serializer = RegisterSerializer() *return *Response({'serializer': serializer}) *def post*(self, request): serializer = RegisterSerializer(data=request.data) * if not* serializer.is_valid(): *return* Response({'serializer': serializer}) serializer.save() *return *redirect('register') My *template (register.html)* is: *{% load rest_framework %}* ** ** **Register** ** {% csrf_token %} {% render_form serializer %} ** ** ** * * I have tried a lot but I could not figure out what wrong I am doing. Any help will surely be appreciated. -- 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/d58d9141-3121-4fdc-91ae-d6b659693c91n%40googlegroups.com.
How do I access User Model field in the Serializer of extended User Model in Django Rest Framework?
I am creating a simple registration/login app in Django Rest Framework using Rest APIs with Django Rest Knox’s authentication, in which, upon registration, user will also upload a CSV File (which is an optional field). I have a Person Model which is an extended (derived or OneToOne) Model of User Model and has FileField for the file to be uploaded. I have two ModelSerializers, one is based on User Model named MainRegisterSerializer and serializes username, email and password fields, and the other is based on Person Model named RegisterSerializer, which serializes FileField and register field (that is initialized with MainRegisterSerializer class’s constructor. Now, in views.py, I am accessing the RegisterSerializer, to get the data from front that which includes username, email and password fields from User Model, and FileField from Person Model. But, when I enter data in front-end and upload the file, and click on POST button, I get the following error: KeyError at /api/v1/register 'username' on the code line user = User.objects.create_user(validated_data['username'], validated_data['email'], validated_data['password'], validated_data['file']) in serializers.py file. My *views.py* is: from rest_framework.response import Response from knox.models import AuthToken from .serializers import RegisterSerializer class RegisterAPI(generics.GenericAPIView): serializer_class = RegisterSerializer def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) user = serializer.save() token = AuthToken.objects.create(user) return Response({ "users": UserSerializer(user, context=self.get_serializer_context()).data, "token": token[1] }) My *serializers.py* is: from .models import Person from django.contrib.auth.models import User from rest_framework import serializers class MainRegisterSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('username', 'email', 'password') class RegisterSerializer(serializers.ModelSerializer): register = MainRegisterSerializer() class Meta: model = Person fields = ['register', 'file',] optional_fields = ['file',] extra_kwargs = {'password': {'write_only': True}} def create(self, validated_data): user = User.objects.create_user(validated_data['username'], validated_data['email'], validated_data['password'], validated_data['file']) return user My *models.py* is: from django.db import models. from django.contrib.auth.models import User class Person(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) file = models.FileField(verbose_name="CSV File") I have already worked around by trying various solutions, but none of them worked for me, that’s why I am posting the question. Any help will surely be appreciated. Thanks -- 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/a7e4ca7f-cc37-456f-8a12-f95a6687e6a6n%40googlegroups.com.
Need ValidationError along with params in Django REST Framework
Hello all, The ValidationError raised by Django REST Framework doesn't include params like how Django's Validation error includes it. The REST Framework catches Django's Validation Error and raises it's Validation error which doesn't include params. Is there any way to keep params in the REST Framework ValidationError which are raised by Django's Validation Error? Regards, Kedar -- 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/214baf78-6aa1-474c-8076-13734cc4b898n%40googlegroups.com.
Re: Firebase integration with Django REST framework
Hi Ilija, I've had personal experience with working on Django REST Framework + Firebase. There are many good technical blogs out there to help us integrate Firebase services with DRF. I would be able to give you some recommendations but would like to know which Firebase service you would be interested to integrate with Django REST Framework ? https://firebase.google.com/products-build https://firebase.google.com/products-release https://firebase.google.com/products-engage On Tuesday, March 8, 2022 at 4:11:16 AM UTC+5:30 tavolo@gmail.com wrote: > Dear all! > does anybody have some recommendation about good resources for integration > of Django REST framework with Firebase? > > And generally what is experience in integration of this two? > > Thanks in advance, > Ilija > -- 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/bc0f5c4b-854c-40db-95e3-a2b9c6066632n%40googlegroups.com.
Firebase integration with Django REST framework
Dear all! does anybody have some recommendation about good resources for integration of Django REST framework with Firebase? And generally what is experience in integration of this two? Thanks in advance, Ilija -- 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/e0c2bd0b-6902-48ba-be68-b13545a19c92n%40googlegroups.com.
Recomendation for forum package/app for Django Rest Framework
Hi all, Can I please have recomendations for a plugable app/package for my basic forum in DRF, The required features are - Topics - Post against topics - Followers of a topic - Comments on a post - Replies on comments - Reporting a comment In future I might need to extend the functionality so please recoment keeping this in mind. Thanks in advance. -- 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/245307f1-5a53-4b17-96c9-4b9aa85b6813n%40googlegroups.com.
wahat are the basics of django rest framework to start.
I am a begginer, trying to learn django and django rest framework. i have few questions. Don't know whether they are silly to ask or not. please bear with me. 1. what is the simple definition or api and microservice. what's the differnce between these two? 2. why we use api? 3. how to know it's an api? -- 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/ad2b20c1-63cc-431a-97f4-ef7fa6a00f45n%40googlegroups.com.
Re: Query on building a business logic layer using django rest framework
Thanks Umair for your good suggestion , will check that, would there be any reference implementation available anywhere on github which can be referred , please let me know On Fri, Sep 3, 2021 at 11:55 AM Umair Ramzan wrote: > > You can always use the functions avaible on Django Queryset and Models. You > can build your business logic by manipulating the data. a better way to do > this is to separate your business logic from the view and models. you can > always write a function let's say "def my_business_logic" with all the logic > that you need to implement and keep in a separate module. you can always call > this from your view code or anywhere you need. > > > On Thursday, September 2, 2021 at 8:49:23 PM UTC+5:30 Deepak Kotian wrote: >> >> Just to elaborate, primarily, I am keen looking at a lot of procedural kind >> of validation/checks like, >> if data is not found in 'x' table, >> then insert in 'y' table from the UI form data >> else insert in 'y' table from the 'x' data >> There could be more such if & else with multiple data >> Could someone please suggest good way to do it. >> >> >> On Thursday, September 2, 2021 at 2:24:23 AM UTC+5:30 Deepak Kotian wrote: >>> >>> Hi, >>> I am new to django rest framework and what I see that the CRUD operation on >>> a database tables using model is easy and quick. >>> Query: >>> If I want to build a business logic with REST api implemented in django >>> with multiple table hits in the same rest api end point and may >>> create/update multiple or single table and validate inputs from users from >>> frontend side . >>> Is there any good reference example implementation in such scenarios or >>> any pointers would help. Please kjndly let me know. >>> >>> Thank you >>> Deepak > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Django REST framework" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-rest-framework/zwJEgCzdnaY/unsubscribe. > To unsubscribe from this group and all its topics, 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/b38b7a94-0712-4c3a-99e3-6feeb1f6c3ecn%40googlegroups.com. -- 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/CACZqC-pzcj-%3Dx-TgxzPrZt-6jAhcCtx%2BBz3sAtg24y03HRPq%2BQ%40mail.gmail.com.
Re: Query on building a business logic layer using django rest framework
You can always use the functions avaible on Django Queryset and Models. You can build your business logic by manipulating the data. a better way to do this is to separate your business logic from the view and models. you can always write a function let's say "def my_business_logic" with all the logic that you need to implement and keep in a separate module. you can always call this from your view code or anywhere you need. On Thursday, September 2, 2021 at 8:49:23 PM UTC+5:30 Deepak Kotian wrote: > Just to elaborate, primarily, I am keen looking at a lot of procedural > kind of validation/checks like, > if data is not found in 'x' table, > then insert in 'y' table from the UI form data > else insert in 'y' table from the 'x' data > There could be more such if & else with multiple data > Could someone please suggest good way to do it. > > > On Thursday, September 2, 2021 at 2:24:23 AM UTC+5:30 Deepak Kotian wrote: > >> Hi, >> I am new to django rest framework and what I see that the CRUD operation >> on a database tables using model is easy and quick. >> Query: >> If I want to build a business logic with REST api implemented in django >> with multiple table hits in the same rest api end point and may >> create/update multiple or single table and validate inputs from users >> from frontend side . >> Is there any good reference example implementation in such scenarios or >> any pointers would help. Please kjndly let me know. >> >> Thank you >> Deepak >> > -- 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/b38b7a94-0712-4c3a-99e3-6feeb1f6c3ecn%40googlegroups.com.
Re: Query on building a business logic layer using django rest framework
Just to elaborate, primarily, I am keen looking at a lot of procedural kind of validation/checks like, if data is not found in 'x' table, then insert in 'y' table from the UI form data else insert in 'y' table from the 'x' data There could be more such if & else with multiple data Could someone please suggest good way to do it. On Thursday, September 2, 2021 at 2:24:23 AM UTC+5:30 Deepak Kotian wrote: > Hi, > I am new to django rest framework and what I see that the CRUD operation > on a database tables using model is easy and quick. > Query: > If I want to build a business logic with REST api implemented in django > with multiple table hits in the same rest api end point and may > create/update multiple or single table and validate inputs from users > from frontend side . > Is there any good reference example implementation in such scenarios or > any pointers would help. Please kjndly let me know. > > Thank you > Deepak > -- 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/a3562cfa-1d9f-4c7b-be64-a32d5a1c5fa7n%40googlegroups.com.
Query on building a business logic layer using django rest framework
Hi, I am new to django rest framework and what I see that the CRUD operation on a database tables using model is easy and quick. Query: If I want to build a business logic with REST api implemented in django with multiple table hits in the same rest api end point and may create/update multiple or single table and validate inputs from users from frontend side . Is there any good reference example implementation in such scenarios or any pointers would help. Please kjndly let me know. Thank you Deepak -- 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/CACZqC-r%2BL_wr%3Dh2MdM1PMMUFh92QTtWy9_QHr%3DfeEum%3DoD6Jcg%40mail.gmail.com.
Re: Bad request Django rest framework
Thank you for your answer but I already resovled, now I have other question, how can do for detect if model has changed for example post or put? How to do that django rest, thank you again Le lun. 26 juil. 2021 20:20, Mustefa Kamil a écrit : > At model.py change this > avatar = models.ImageField(upload_to='avatar', blank=True, null=True) > > On Saturday, July 24, 2021 at 2:39:31 PM UTC+3 manohiso...@gmail.com > wrote: > >> >> Hello everyone >> A few days ago I made a school project which consists in doing chat or >> almost mini social network, I use as backend django rest framework because >> it is easy and fast for development, and I use as front-end Kivy client. But >> I encountered a problem that I can't solve it, obviously I searched >> everything on the web but it gives me the same result, here is my code: >> models.py: >> class Profile(models.Model): >> #user = models.OneToOneField(User) >> name = models.CharField(max_length=20) >> avatar = models.ImageField(upload_to='avatar', blank=True) >> def __str__(self): >> return self.name >> >> serializers.py: >> class Base64ImageField(serializers.ImageField): >> >> def to_internal_value(self, data): >> >> >> if isinstance(data, six.string_types): >> if 'data:' in data and ';base64,' in data: >> header, data = data.split(';base64,') >> >> try: >> decoded_file = base64.b64decode(data) >> except TypeError: >> self.fail('invalid_image') >> >> file_name = str(uuid.uuid4())[:12] # 12 characters are more >> than enough. >> file_extension = self.get_file_extension(file_name, >> decoded_file) >> complete_file_name = "%s.%s" % (file_name, file_extension, ) >> data = ContentFile(decoded_file, name=complete_file_name) >> >> return super(Base64ImageField, self).to_internal_value(data) >> >> def get_file_extension(self, file_name, decoded_file): >> >> >> extension = imghdr.what(file_name, decoded_file) >> extension = "jpg" if extension == "jpeg" else extension >> >> return extension >> >> >> class ProfileSerializer(serializers.ModelSerializer): >> avatar = Base64ImageField(max_length=None, use_url=True) >> >> class Meta: >> model = Profile >> fields = ('id','name','avatar',) >> >> views.py: >> class ProfileViewSet(viewsets.ModelViewSet): >> queryset = Profile.objects.all() >> serializer_class = ProfileSerializer >> parser_classes = (MultiPartParser, JSONParser) >> >> And in my front-end client: >> def create_user(self, *args): >> username = self.sm.get_screen('signin_screen').ids.username.text >> password = self.sm.get_screen('signin_screen').ids.sign_pass1.text >> email = self.sm.get_screen('signin_screen').ids.email.text >> image = self.path >> with open(self.path, "rb") as img_file: >> my_string = base64.b64encode(img_file.read()) >> print() >> img = my_string.decode('utf-8') >> >> params = json.dumps({'name': username, 'avatar': img}) >> headers = {'Content-type': 'application/json', >> 'Accept': 'application/json'} >> req = UrlRequest('http://127.0.0.1:8000/api/profile/', >> method='POST', on_success=self.user_created, >> on_failure=self.user_login_error, req_body=params, >> req_headers=headers, >> ca_file=cfi.where(),verify=True, on_error=self.error, debug=True) >> >> If I execute this code it returns me: >> Bad Request: /api/profile/ >> [24/Jul/2021 11:32:49] "POST /api/profile/ HTTP/1.1" 400 418 >> >> Please how can resolve this error? >> >> thank you very much >> > -- > 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/0fd7980d-8408-4108-a935-dfb1faed2fa8n%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/0fd7980d-8408-4108-a935-dfb1faed2fa8n%40googlegroups.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/CAES5TeyABgUGawCyvFKyFmZLczTJbPFi_j8OX16ntmy%3DQDvWpA%40mail.gmail.com.
Re: Bad request Django rest framework
At model.py change this avatar = models.ImageField(upload_to='avatar', blank=True, null=True) On Saturday, July 24, 2021 at 2:39:31 PM UTC+3 manohiso...@gmail.com wrote: > > Hello everyone > A few days ago I made a school project which consists in doing chat or > almost mini social network, I use as backend django rest framework because > it is easy and fast for development, and I use as front-end Kivy client. But > I encountered a problem that I can't solve it, obviously I searched > everything on the web but it gives me the same result, here is my code: > models.py: > class Profile(models.Model): > #user = models.OneToOneField(User) > name = models.CharField(max_length=20) > avatar = models.ImageField(upload_to='avatar', blank=True) > def __str__(self): > return self.name > > serializers.py: > class Base64ImageField(serializers.ImageField): > > def to_internal_value(self, data): > > > if isinstance(data, six.string_types): > if 'data:' in data and ';base64,' in data: > header, data = data.split(';base64,') > > try: > decoded_file = base64.b64decode(data) > except TypeError: > self.fail('invalid_image') > > file_name = str(uuid.uuid4())[:12] # 12 characters are more > than enough. > file_extension = self.get_file_extension(file_name, > decoded_file) > complete_file_name = "%s.%s" % (file_name, file_extension, ) > data = ContentFile(decoded_file, name=complete_file_name) > > return super(Base64ImageField, self).to_internal_value(data) > > def get_file_extension(self, file_name, decoded_file): > > > extension = imghdr.what(file_name, decoded_file) > extension = "jpg" if extension == "jpeg" else extension > > return extension > > > class ProfileSerializer(serializers.ModelSerializer): > avatar = Base64ImageField(max_length=None, use_url=True) > > class Meta: > model = Profile > fields = ('id','name','avatar',) > > views.py: > class ProfileViewSet(viewsets.ModelViewSet): > queryset = Profile.objects.all() > serializer_class = ProfileSerializer > parser_classes = (MultiPartParser, JSONParser) > > And in my front-end client: > def create_user(self, *args): > username = self.sm.get_screen('signin_screen').ids.username.text > password = self.sm.get_screen('signin_screen').ids.sign_pass1.text > email = self.sm.get_screen('signin_screen').ids.email.text > image = self.path > with open(self.path, "rb") as img_file: > my_string = base64.b64encode(img_file.read()) > print() > img = my_string.decode('utf-8') > > params = json.dumps({'name': username, 'avatar': img}) > headers = {'Content-type': 'application/json', > 'Accept': 'application/json'} > req = UrlRequest('http://127.0.0.1:8000/api/profile/', > method='POST', on_success=self.user_created, > on_failure=self.user_login_error, req_body=params, > req_headers=headers, > ca_file=cfi.where(),verify=True, on_error=self.error, debug=True) > > If I execute this code it returns me: > Bad Request: /api/profile/ > [24/Jul/2021 11:32:49] "POST /api/profile/ HTTP/1.1" 400 418 > > Please how can resolve this error? > > thank you very much > -- 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/0fd7980d-8408-4108-a935-dfb1faed2fa8n%40googlegroups.com.
Bad request Django rest framework
Hello everyone A few days ago I made a school project which consists in doing chat or almost mini social network, I use as backend django rest framework because it is easy and fast for development, and I use as front-end Kivy client. But I encountered a problem that I can't solve it, obviously I searched everything on the web but it gives me the same result, here is my code: models.py: class Profile(models.Model): #user = models.OneToOneField(User) name = models.CharField(max_length=20) avatar = models.ImageField(upload_to='avatar', blank=True) def __str__(self): return self.name serializers.py: class Base64ImageField(serializers.ImageField): def to_internal_value(self, data): if isinstance(data, six.string_types): if 'data:' in data and ';base64,' in data: header, data = data.split(';base64,') try: decoded_file = base64.b64decode(data) except TypeError: self.fail('invalid_image') file_name = str(uuid.uuid4())[:12] # 12 characters are more than enough. file_extension = self.get_file_extension(file_name, decoded_file) complete_file_name = "%s.%s" % (file_name, file_extension, ) data = ContentFile(decoded_file, name=complete_file_name) return super(Base64ImageField, self).to_internal_value(data) def get_file_extension(self, file_name, decoded_file): extension = imghdr.what(file_name, decoded_file) extension = "jpg" if extension == "jpeg" else extension return extension class ProfileSerializer(serializers.ModelSerializer): avatar = Base64ImageField(max_length=None, use_url=True) class Meta: model = Profile fields = ('id','name','avatar',) views.py: class ProfileViewSet(viewsets.ModelViewSet): queryset = Profile.objects.all() serializer_class = ProfileSerializer parser_classes = (MultiPartParser, JSONParser) And in my front-end client: def create_user(self, *args): username = self.sm.get_screen('signin_screen').ids.username.text password = self.sm.get_screen('signin_screen').ids.sign_pass1.text email = self.sm.get_screen('signin_screen').ids.email.text image = self.path with open(self.path, "rb") as img_file: my_string = base64.b64encode(img_file.read()) print() img = my_string.decode('utf-8') params = json.dumps({'name': username, 'avatar': img}) headers = {'Content-type': 'application/json', 'Accept': 'application/json'} req = UrlRequest('http://127.0.0.1:8000/api/profile/', method='POST', on_success=self.user_created, on_failure=self.user_login_error, req_body=params, req_headers=headers, ca_file=cfi.where(),verify=True, on_error=self.error, debug=True) If I execute this code it returns me: Bad Request: /api/profile/ [24/Jul/2021 11:32:49] "POST /api/profile/ HTTP/1.1" 400 418 Please how can resolve this error? thank you very much -- 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/6534011f-5813-485f-9b13-9578a9a0b157n%40googlegroups.com.
django-rest-framework-social-oauth2 & Client secret
Hi, I am working on setting up django-rest-framework-social-oauth2 and I am able to get the tests in the official README to run. However, the few examples in the docs require the Client Secret in the URL. As I don't want to publish the Client Secret in an SPA, I am wondering if there is another way to leverage this module ( e.g. Authorization Code w/ PKCE ). Thanks for any insights on this. -- 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/CAMZO7wLNidnKx-XLSMuddSADLeF%2BHY0enM9UUQUXfOp6H6QiYw%40mail.gmail.com.
GraphWrap: extend your Django REST Framework API with a GraphQL interface with just two of lines of code.
Hi all, I recently built a Django REST Framework extension library, which, by adding only two of lines of code to your django project, can extend an existing Django REST Framework API with a GraphQL <https://graphql.org/learn/> interface. Pypi: https://pypi.org/project/graph-wrap/ Github: https://github.com/PaulGilmartin/graph_wrap Highlights: - The dynamic nature of the build of the GraphQL layer means that you can continue to develop your existing REST based API and know that the GraphQL schema will be kept up-to-date automatically. - Since the GraphQL layer is using the REST API under-the-hood, you can be sure that important things like serialization, authentication, authorization and filtering will be consistent between your REST view and the corresponding GraphQL type. - You no longer need to "over expose" fields from nested apis - the client can make use of the GraphQL layer to fetch data they need. This can lead to significant performance boosts in certain circumstances (One of the advantages of GraphQL queries is that they solve the n+1 problem <https://itnext.io/what-is-the-n-1-problem-in-graphql-dd4921cb3c1a> which occurs with traditional REST-based APIs). See Which problems does GraphWrap address <https://github.com/PaulGilmartin/graph_wrap#which-problems-does-graphwrap-address> for more. GraphWrap was originally designed for (and still supports) django-tastypie <https://django-tastypie.readthedocs.io/en/latest/>, where it was tested on a production-scale API. The latest release (0.1.0) adds Django REST Framework. I've done fairly extensive testing locally, but haven't had the opportunity to really test how GraphWrap fairs with a production-scale Django REST Framework API. Any feedback on how well it is/is not working would be greatly appreciated! -- 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/12ba4e51-4a33-4b0a-acc4-44a712a83271n%40googlegroups.com.
Django Rest Framework Serializer not printing nested relationship
I've got established a relationship between 2 models: Order and OrderLine. I've created serializers for both of them following the DRF documentation, yet when printing the serializer.data the nested objects don't show. Here are my models: class Order(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) session_id = models.CharField(max_length=256) class OrderLine(models.Model): order_id = models.ForeignKey(Order, on_delete=models.DO_NOTHING) product_id = models.ForeignKey(Product, on_delete=models.DO_NOTHING) price = models.DecimalField(decimal_places=2, max_digits=20) quantity = models.IntegerField() total = models.DecimalField(decimal_places=2, max_digits=20) created_at = models.DateField(auto_now_add=True) updated_at = models.DateField(auto_now=True) These are the serializers: from rest_framework import serializers from .models import Order, OrderLine class OrderLineSerializer(serializers.ModelSerializer): """ OrderLine serializer """ class Meta: model = OrderLine fields = ['product_id', 'price', 'quantity', 'total'] class OrderSerializer(serializers.ModelSerializer): """ Order serializer """ items = OrderLineSerializer(many=True, read_only=True) class Meta: model = Order fields = ['session_id', 'subtotal', 'total', 'items'] read_only_fields = ['id'] and this is the view: class OrderAPIViewSet(viewsets.ViewSet): def create(self, request): order = Order.objects.create(session_id=request.data['session_id']) for item in request.data['items']: product = Product.objects.get(pk=item['product_id']) total = Decimal(item['price'] * item['quantity']) OrderLine.objects.create( order_id=order, product_id=product, price=Decimal(item['price']), quantity=item['quantity'], total=total ) serializer = OrderSerializer(instance=order) print("HERE") print(serializer.data) return Response(status=status.HTTP_200_OK) >From my REST client I'm posting the following object: { "session_id":uuid, "items": [ { "product_id": product.id, "price": 5.80, "quantity": 2, } ] } but when the print statement in the view is executed this is what's being printed: { "session_id":"4def7bdb-dedb-46aa-9c70-1d9e4f522149", "subtotal":"0.00", "total":"0.00" } notice the the items subresource is not being included. What am i missing? -- 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/9da5a377-7db2-43eb-a539-07547351b2d8n%40googlegroups.com.
Re: Reset password in django rest framework
https://www.youtube.com/watch?v=2kKwPk5qPUs&t=1285s this will help in reseting your password using rest framework On Wednesday, 2 December 2020 at 23:15:37 UTC+5:30 yashwanth balanagu wrote: > Hey guys, > > Anyone know how to do reset password or forgot password in django rest > framework > > Mainly resources are very less. so if anyone know please let me know > -- 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/f7a241d7-3775-418a-8d92-cfda613bdfacn%40googlegroups.com.
Re: Reset password in django rest framework
run in terminal: python manage.py changepassword user_name On Wednesday, December 2, 2020 at 11:15:37 PM UTC+5:30 yashwanth balanagu wrote: > Hey guys, > > Anyone know how to do reset password or forgot password in django rest > framework > > Mainly resources are very less. so if anyone know please let me know > -- 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/cf1bfd1a-1e72-41b6-8de4-4fd599a52a6dn%40googlegroups.com.
Reset password in django rest framework
Hey guys, Anyone know how to do reset password or forgot password in django rest framework Mainly resources are very less. so if anyone know please let me know -- 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/6756da1c-5b63-4386-b38e-87745659cbcdn%40googlegroups.com.
Re: How to convert Stored procedure logic to Django rest framework
I've converted many systems in my life and I have always found it best to use the old system as a guide and not try to use anything from the old system at all. Know what it is that you are trying to do, understand what the inputs and outputs are, and write new code. The old system would therefore be a guide as to what these inputs and outputs are, in other words, it defines your use cases. With that said you haven't mentioned what DB your old .NET system is using. The only DB I ever use anymore with Django is PostgreSQL, it is also supported better than any other DB. I do consult work specifically for these types of cases. ~Carl On Sun, Nov 15, 2020 at 1:41 PM brijesh dutta wrote: > Hi All, > > i am new to DRF > > We have an existing application in .NET which uses complex stored > procedures > (mainly taking dataset as a paramter and inserting the data into multiple > tables) > we have an initiative to move the backend to Django rest framework > > hence just wanted suggestions what is the best practice in DRF for such > use cases and if any one could direct me o some useful content to get > started > > Thank You > Regards > -Brijesh > > > -- > 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/214d12ab-ac5c-4ee4-871f-9c4e2648d09an%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/214d12ab-ac5c-4ee4-871f-9c4e2648d09an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- --- Carl J. Nobile (Software Engineer) carl.nob...@gmail.com ------- -- 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/CAGQqDQL0nBO%2BrKO5ndX3oAH_exxzoVD58JeMQF_U%3DJ-5GZK9Rw%40mail.gmail.com.
How to convert Stored procedure logic to Django rest framework
Hi All, i am new to DRF We have an existing application in .NET which uses complex stored procedures (mainly taking dataset as a paramter and inserting the data into multiple tables) we have an initiative to move the backend to Django rest framework hence just wanted suggestions what is the best practice in DRF for such use cases and if any one could direct me o some useful content to get started Thank You Regards -Brijesh -- 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/214d12ab-ac5c-4ee4-871f-9c4e2648d09an%40googlegroups.com.
Re: How to make my own model authentication and authorizations in Django Rest Framework
On Thu, Oct 1, 2020 at 1:24 AM Osama Imran wrote: > But I want to know people approaches how they proceed in this scenario as > you know there are tons of tutorial available but not suitable for my > requirements. > How people may approach this in a particular way is found in the tutorials you are referring to. If that doesn't suit your requirements, the docs provide a comprehensive way of building them tailored to your needs upon the software design (it is "best" in this sense) - which was the answer to your generic question :) > On Thu, 1 Oct 2020, 5:26 am Carl Nobile, wrote: > >> It's always best to read the docs before asking questions here because in >> many instances there are many answers to your questions. >> >> Here's a link to the DRF docs for authentication: >> https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/ >> >> ~Carl >> >> On Wed, Sep 30, 2020 at 2:45 PM Osama Imran wrote: >> >>> Hello All, >>> I am new to Django rest frame work and my questions is how I can apply >>> Authentication and Authorizations to any model for API view which I have >>> developed from scratch and what is the best way to implement these >>> concepts. please help. >>> Thank you >>> >>> -- >>> 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/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-rest-framework/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> >> ------- >> Carl J. Nobile (Software Engineer) >> carl.nob...@gmail.com >> >> --- >> >> -- >> 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/CAGQqDQJGae1U-RGQCaGnShr0zj5159MJck3s6kJ6__mR4Hn9AQ%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQJGae1U-RGQCaGnShr0zj5159MJck3s6kJ6__mR4Hn9AQ%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/CAJ8LUf7pJ_ex%3Do%2Bjc6ggD%2BVO4qAnR4GUcZxZ8Z%2B%3DSOvo9jePzg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAJ8LUf7pJ_ex%3Do%2Bjc6ggD%2BVO4qAnR4GUcZxZ8Z%2B%3DSOvo9jePzg%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%2BFDnhJW%3DtN%3DOTvBzANAotO45iirjUv4zM6ta4hXF4aeEcOQJQ%40mail.gmail.com.
Re: How to make my own model authentication and authorizations in Django Rest Framework
But I want to know people approaches how they proceed in this scenario as you know there are tons of tutorial available but not suitable for my requirements. On Thu, 1 Oct 2020, 5:26 am Carl Nobile, wrote: > It's always best to read the docs before asking questions here because in > many instances there are many answers to your questions. > > Here's a link to the DRF docs for authentication: > https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/ > > ~Carl > > On Wed, Sep 30, 2020 at 2:45 PM Osama Imran wrote: > >> Hello All, >> I am new to Django rest frame work and my questions is how I can apply >> Authentication and Authorizations to any model for API view which I have >> developed from scratch and what is the best way to implement these >> concepts. please help. >> Thank you >> >> -- >> 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/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com >> <https://groups.google.com/d/msgid/django-rest-framework/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > --- > Carl J. Nobile (Software Engineer) > carl.nob...@gmail.com > > --- > > -- > 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/CAGQqDQJGae1U-RGQCaGnShr0zj5159MJck3s6kJ6__mR4Hn9AQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQJGae1U-RGQCaGnShr0zj5159MJck3s6kJ6__mR4Hn9AQ%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/CAJ8LUf7pJ_ex%3Do%2Bjc6ggD%2BVO4qAnR4GUcZxZ8Z%2B%3DSOvo9jePzg%40mail.gmail.com.
Re: How to make my own model authentication and authorizations in Django Rest Framework
It's always best to read the docs before asking questions here because in many instances there are many answers to your questions. Here's a link to the DRF docs for authentication: https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/ ~Carl On Wed, Sep 30, 2020 at 2:45 PM Osama Imran wrote: > Hello All, > I am new to Django rest frame work and my questions is how I can apply > Authentication and Authorizations to any model for API view which I have > developed from scratch and what is the best way to implement these > concepts. please help. > Thank you > > -- > 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/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- --- Carl J. Nobile (Software Engineer) carl.nob...@gmail.com --- -- 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/CAGQqDQJGae1U-RGQCaGnShr0zj5159MJck3s6kJ6__mR4Hn9AQ%40mail.gmail.com.
How to make my own model authentication and authorizations in Django Rest Framework
Hello All, I am new to Django rest frame work and my questions is how I can apply Authentication and Authorizations to any model for API view which I have developed from scratch and what is the best way to implement these concepts. please help. Thank you -- 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/6c08b363-6326-45aa-a748-ffae253c66d3n%40googlegroups.com.
how to update child record from parent url aceess in django rest framework
https://stackoverflow.com/questions/64097797/how-to-update-child-record-from-parent-url-aceess-in-django-rest-framework please check this link -- 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/a877b876-52de-4ff0-9c9b-87e1a083e4ddn%40googlegroups.com.
Updating models with unique fields in Django Rest Framework
Can one solve this issue https://stackoverflow.com/q/64099264/7999665 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 django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/72356fe6-8b34-4ba6-a4ba-11305977f1d6n%40googlegroups.com.
duplicate key value violates unique constraint django rest framework
I have *App named Company* and in *models.py* there is a model named *CompanyProfile* models.py ```python class CompanyProfile(models.Model): id = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, verbose_name='ID',) full_name= models.CharField(max_length=255, unique = True, default='NA') contact_person_email = models.EmailField(unique=True, null=True, blank=True) def __str__(self): return str(self.full_name) ``` serializers.py python class CompanyProfileSerializer(serializers.ModelSerializer): """List all the Company Profile""" class Meta: model = CompanyProfile fields = '__all__' read_only_fields = ['id'] ``` views.py python class CompanyProfileViewSet(viewsets.ModelViewSet): """Update and Detail for Company Profile""" queryset = CompanyProfile.objects.all() serializer_class = CompanyProfileSerializer permission_classes = (permissions.IsAuthenticated,) lookup_field = 'id' def update(self, request, id ,*args, **kwargs): instance = self.get_object() import pdb; pdb.set_trace() if instance.full_name != request.data.get("full_name"): instance.full_name = request.data.get("full_name") if instance.contact_person_email != request.data.get("contact_person_email"): instance.contact_person_email = request.data.get("contact_person_email") instance.save() return super().update(request, *args, **kwargs) Now if you see above am actually comparing each field and checking weather update is possible there or if the field needs to be updated? **1. Doing this one each field is quite cumbersome** as I have already set the required validation But now I have to check on each field whether the user has updated them or not! **2. If I don't have an update in any of the fields then it gives me this error** ``` already exists ``` and sometimes as some field are marked unique in that case ``` duplicate key value violates unique constraint ``` -- I understand Technically it's correct is there any simple approach rather than this level of workaround. -- 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/HK0PR01MB1905C791B0FF6D78571FAB35A7340%40HK0PR01MB1905.apcprd01.prod.exchangelabs.com.
Re: ListCreateAPIView Django rest framework Method \"POST\" not allowed
Yes, there was an issue with the router only I added this and now it's working ```path(''check/", include(router.urls)),``` Thanks & Regards On Friday, September 25, 2020 at 5:42:24 PM UTC+5:30 Xavier Ordoquy wrote: > Hi, > > What does your router look like ? > > Regards, > Xavier O. > Le 25 sept. 2020 à 13:48 +0200, Pradyum Gupta , a > écrit : > > See I don't know this is actually a very weird error that am receiving. > > > > Inside *Company App* > > > > views.py > > ```python3 > > class CompanyView(generics.ListCreateAPIView): > > queryset = CompanyProfile.objects.all() > > serializer_class = RegisterationCompanySerializer > > permission_classes = (permissions.IsAuthenticated,) > > > > def post(self, request, *args, **kwargs): > > import pdb; pdb.set_trace() #check weather post request is getting > called? > > return self.create(request, *args, **kwargs) > > > > def get_serializer(self, *args, **kwargs): > > import pdb; pdb.set_trace() #check weather post serializer is > getting called? > > user_id = self.request.user.id > > serializer_class = self.get_serializer_class() > > . > > kwargs['data'] = draft_request_data > > return serializer_class(*args, **kwargs) > > > > ``` > > > > urls.py inside the company app > > ``` > > urlpatterns = [ > > path('', include(router.urls)), > > > > ## Register Company Process > > # path('List/', ListCompanyView.as_view()), > > path('Reg/', CompanyView.as_view()), > > ] > > > > ``` > > serializer.py > > ```python > > class RegisterationCompanySerializer(serializers.ModelSerializer): > > > > class Meta: > > model = CompanyProfile > > fields = '__all__' > > extra_kwargs = { > > 'short_name': {'required': True}, > > .. > > 'user' : {'required': True}, > >} > > > > ``` > > > > models.py > > ```python > > class CompanyProfile(models.Model): > > id = models.UUIDField(default=uuid.uuid4, > > editable=False, > > primary_key=True, > > verbose_name='ID',) > >.. > >verified = models.BooleanField(default=False) > > > > def __str__(self): > > return str(self.id) > > ``` > > > > Also, note the ```company``` is present in ```INSTALLED_APPS``` > > > > But error am receiving this is on postman > > ``` > > { > > "detail": "Method \"POST\" not allowed." > > } > > ``` > > > > on the terminal and tried PDB to check whether the function is getting > called > > ``` > > Method Not Allowed: /company/Reg/ > > [Date and Time] "POST /company/Reg/ HTTP/1.1" 405 41 > > ``` > > > > let me know if you are looking for more details. > > > > Thanks in advance > > > > Regards > > Please also find the same question here > https://stackoverflow.com/q/64063496/7999665 > > > > -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/PU1PR04MB23892F217077E14B042A0CB1A7360%40PU1PR04MB2389.apcprd04.prod.outlook.com > > <https://groups.google.com/d/msgid/django-rest-framework/PU1PR04MB23892F217077E14B042A0CB1A7360%40PU1PR04MB2389.apcprd04.prod.outlook.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/b2810f50-1502-4c3e-96e8-d29af177c021n%40googlegroups.com.
Re: ListCreateAPIView Django rest framework Method \"POST\" not allowed
Hi, What does your router look like ? Regards, Xavier O. Le 25 sept. 2020 à 13:48 +0200, Pradyum Gupta , a écrit : > See I don't know this is actually a very weird error that am receiving. > > Inside *Company App* > > views.py > ```python3 > class CompanyView(generics.ListCreateAPIView): > queryset = CompanyProfile.objects.all() > serializer_class = RegisterationCompanySerializer > permission_classes = (permissions.IsAuthenticated,) > > def post(self, request, *args, **kwargs): > import pdb; pdb.set_trace() #check weather post request is getting > called? > return self.create(request, *args, **kwargs) > > def get_serializer(self, *args, **kwargs): > import pdb; pdb.set_trace() #check weather post serializer is getting > called? > user_id = self.request.user.id > serializer_class = self.get_serializer_class() > . > kwargs['data'] = draft_request_data > return serializer_class(*args, **kwargs) > > ``` > > urls.py inside the company app > ``` > urlpatterns = [ > path('', include(router.urls)), > > ## Register Company Process > # path('List/', ListCompanyView.as_view()), > path('Reg/', CompanyView.as_view()), > ] > > ``` > serializer.py > ```python > class RegisterationCompanySerializer(serializers.ModelSerializer): > > class Meta: > model = CompanyProfile > fields = '__all__' > extra_kwargs = { > 'short_name': {'required': True}, > .. > 'user' : {'required': True}, > } > > ``` > > models.py > ```python > class CompanyProfile(models.Model): > id = models.UUIDField(default=uuid.uuid4, > editable=False, > primary_key=True, > verbose_name='ID',) > .. > verified = models.BooleanField(default=False) > > def __str__(self): > return str(self.id) > ``` > > Also, note the ```company``` is present in ```INSTALLED_APPS``` > > But error am receiving this is on postman > ``` > { > "detail": "Method \"POST\" not allowed." > } > ``` > > on the terminal and tried PDB to check whether the function is getting called > ``` > Method Not Allowed: /company/Reg/ > [Date and Time] "POST /company/Reg/ HTTP/1.1" 405 41 > ``` > > let me know if you are looking for more details. > > Thanks in advance > > Regards > Please also find the same question here > https://stackoverflow.com/q/64063496/7999665 > > -- > 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/PU1PR04MB23892F217077E14B042A0CB1A7360%40PU1PR04MB2389.apcprd04.prod.outlook.com. -- 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/b3ef8c97-d65e-4a02-810e-018edcceea2d%40Spark.
ListCreateAPIView Django rest framework Method \"POST\" not allowed
See I don't know this is actually a very weird error that am receiving. Inside *Company App* views.py ```python3 class CompanyView(generics.ListCreateAPIView): queryset = CompanyProfile.objects.all() serializer_class = RegisterationCompanySerializer permission_classes = (permissions.IsAuthenticated,) def post(self, request, *args, **kwargs): import pdb; pdb.set_trace() #check weather post request is getting called? return self.create(request, *args, **kwargs) def get_serializer(self, *args, **kwargs): import pdb; pdb.set_trace() #check weather post serializer is getting called? user_id = self.request.user.id serializer_class = self.get_serializer_class() . kwargs['data'] = draft_request_data return serializer_class(*args, **kwargs) ``` urls.py inside the company app ``` urlpatterns = [ path('', include(router.urls)), ## Register Company Process # path('List/', ListCompanyView.as_view()), path('Reg/', CompanyView.as_view()), ] ``` serializer.py ```python class RegisterationCompanySerializer(serializers.ModelSerializer): class Meta: model = CompanyProfile fields = '__all__' extra_kwargs = { 'short_name': {'required': True}, .. 'user' : {'required': True}, } ``` models.py ```python class CompanyProfile(models.Model): id = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, verbose_name='ID',) .. verified = models.BooleanField(default=False) def __str__(self): return str(self.id) ``` Also, note the ```company``` is present in ```INSTALLED_APPS``` But error am receiving this is on postman ``` { "detail": "Method \"POST\" not allowed." } ``` on the terminal and tried PDB to check whether the function is getting called ``` Method Not Allowed: /company/Reg/ [Date and Time] "POST /company/Reg/ HTTP/1.1" 405 41 ``` let me know if you are looking for more details. Thanks in advance Regards Please also find the same question here https://stackoverflow.com/q/64063496/7999665 -- 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/PU1PR04MB23892F217077E14B042A0CB1A7360%40PU1PR04MB2389.apcprd04.prod.outlook.com.
Re: Digest for django-rest-framework@googlegroups.com - 3 updates in 2 topics
Thank you for your kind reply @naveenkumar...@gmail.com. Here is the way that we found to solve this issue. Company App > models.py ```python3 country = models.ForeignKey('login.Country', on_delete=models.SET_NULL, null=True, blank=False) ``` The Project structure was quite large so did not find appropriate to share all of that here. Therefore shared a snippet. Regards Pradyum From: "django-rest-framework@googlegroups.com" Reply to: "django-rest-framework@googlegroups.com" Date: Thursday, 24 September 2020 at 3:16 PM To: Digest recipients Subject: Digest for django-rest-framework@googlegroups.com - 3 updates in 2 topics django-rest-framework@googlegroups.com<%20%20https:/groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/django-rest-framework/topics> Google Groups<https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview> [Image removed by sender.]<https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview> Topic digest View all topics<%20%20https:/groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/django-rest-framework/topics> · Attribute Error in Django model Foreign Key - 2 Updates · Create an invitation link using django rest framework? - 1 Update Attribute Error in Django model Foreign Key <http://groups.google.com/group/django-rest-framework/t/16b95088fdd6bda2?utm_source=digest&utm_medium=email> Pradyum Gupta : Sep 24 09:00AM In My Django Project, there are two apps: Login and Company The **error that am receiving** in this is ```python AttributeError: module 'login.models' has no attribute 'Country' ``` *Company App* > models.py ```python from django.db import models from login import models as LM class CompanyProfile(models.Model): full_name = models.CharField(max_length=255, unique = True) country = models.ForeignKey(LM.Country, on_delete=models.SET_NULL, null=True, blank=False) state = models.ForeignKey(LM.State, on_delete=models.SET_NULL, null=True, blank=False) def __str__(self): return self.full_name ``` *Login App* > models.py python class Country(models.Model): """List of Country""" name = models.CharField(max_length=50, unique= True, default='None') code = models.CharField(max_length=2, unique= True, primary_key=True, default ='NA') def __str__(self): return str(self.code) class State(models.Model): """List fo State""" region = models.CharField(max_length = 255, unique = True, primary_key=True, default='None') country = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True, blank=False, default ='NA') def __str__(self): return self.region Here is test to check that weather is login is getting imported or not ```python def test_import(): try: # import pdb; pdb.set_trace() importlib.find_loader('LM.Country') found = True except ImportError: found = False print(found) ``` Answer is received stands to be True ``` python3 manage.py shell >>> test_import() True ``` Now on other stackoverflow blogs i checked i thought it could be of ```Circlular Import``` But i have already fixed that still am getting this error? Thanks in Advance Regards PS: I have also asked the same question here https://stackoverflow.com/q/64042995/7999665 naveen Kumar : Sep 24 03:07PM +0530 i thinks it will be helpful if you place screenshots of you project file structure as you mentioned along with models, so that people can easily trace out the issue. On Thu, Sep 24, 2020 at 2:30 PM Pradyum Gupta wrote: Back to top Create an invitation link using django rest framework? <http://groups.google.com/group/django-rest-framework/t/6416310b6a449fb6?utm_source=digest&utm_medium=email> Pradyum Gupta : Sep 24 01:18PM +0530 Thank you @Naveen Kumar and @Matemática A3K Will try both the options. Regards Pradyum On Wed, Sep 23, 2020 at 12:12 PM naveen Kumar wrote: Back to top You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page<%20%20https:/groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/django-rest-framework/join>. To unsubscribe from this group and stop receiving emails from it send an email to django-rest-framework+unsubscr...@googlegroups.com<mailto:django-rest-framework+unsubscr...@googlegroups.com>. -- 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/SG2PR04MB2761CEBE4ECB12528CDE0F89A7390%40SG2PR04MB2761.apcprd04.prod.outlook.com.
Re: Create an invitation link using django rest framework?
Thank you @Naveen Kumar and @Matemática A3K Will try both the options. Regards Pradyum On Wed, Sep 23, 2020 at 12:12 PM naveen Kumar wrote: > class TokenGenerator(PasswordResetTokenGenerator): > > def _make_hash_value(self, user, timestamp): > return ( > six.text_type(user.pk) + six.text_type(timestamp) + > six.text_type(user.username) ) > > > account_activation_token = TokenGenerator() > > follow this you can hash both values company, time_age > > On Mon, Sep 21, 2020 at 7:45 PM Pradyum Gupta wrote: > >> am looking for some advice/Mentorship. >> >> wanted to create an *invitation link for onboarding user to a company* >> similarly >> slack does by sending company employees email so that they could directly >> join the company but using the Django rest framework is there any method >> that you can refer? >> >> see things that I have in my mind coming is that I can put company_id in >> hash inside a link and then when a user will come with that hash I can >> compare it and onboard the user. >> >> but in that case, there is no link_time_age I can compare! >> >> is there any method or any crypto algo in which is can convert >> company_UUID into some string and decode back into UUID and then compare it >> through icontains and similarly I can do with time and age of link? >> >> but first of all, is this the right approach? or how do people in a >> company like slack or telegram do? >> >> any kind of help will be really appreciated. >> >> See what am looking for certain guidance or any reference documentation. >> >> -- >> 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/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.com >> <https://groups.google.com/d/msgid/django-rest-framework/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django REST framework" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-rest-framework/ZBYxC2pEn7Y/unsubscribe > . > To unsubscribe from this group and all its topics, 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/CAN9FMSwjSDnfk1HgvjVBwqtSizb79NSWo36aSwiuDfJ-DR7Yhg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAN9FMSwjSDnfk1HgvjVBwqtSizb79NSWo36aSwiuDfJ-DR7Yhg%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/CAPWtzYXBMYxJYrKoRTY8oTnQ0NCrh-P1fFa3GPQdj5H6u%2Bcn4A%40mail.gmail.com.
Re: Create an invitation link using django rest framework?
class TokenGenerator(PasswordResetTokenGenerator): def _make_hash_value(self, user, timestamp): return ( six.text_type(user.pk) + six.text_type(timestamp) + six.text_type(user.username) ) account_activation_token = TokenGenerator() follow this you can hash both values company, time_age On Mon, Sep 21, 2020 at 7:45 PM Pradyum Gupta wrote: > am looking for some advice/Mentorship. > > wanted to create an *invitation link for onboarding user to a company* > similarly > slack does by sending company employees email so that they could directly > join the company but using the Django rest framework is there any method > that you can refer? > > see things that I have in my mind coming is that I can put company_id in > hash inside a link and then when a user will come with that hash I can > compare it and onboard the user. > > but in that case, there is no link_time_age I can compare! > > is there any method or any crypto algo in which is can convert > company_UUID into some string and decode back into UUID and then compare it > through icontains and similarly I can do with time and age of link? > > but first of all, is this the right approach? or how do people in a > company like slack or telegram do? > > any kind of help will be really appreciated. > > See what am looking for certain guidance or any reference documentation. > > -- > 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/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.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/CAN9FMSwjSDnfk1HgvjVBwqtSizb79NSWo36aSwiuDfJ-DR7Yhg%40mail.gmail.com.
Re: Create an invitation link using django rest framework?
On Mon, Sep 21, 2020 at 9:15 AM Pradyum Gupta wrote: > am looking for some advice/Mentorship. > > wanted to create an *invitation link for onboarding user to a company* > similarly > slack does by sending company employees email so that they could directly > join the company but using the Django rest framework is there any method > that you can refer? > > see things that I have in my mind coming is that I can put company_id in > hash inside a link and then when a user will come with that hash I can > compare it and onboard the user. > but in that case, there is no link_time_age I can compare! > You can generate a hash and store a timestamp in the model (Django model), then code the logic you are referring in the view (you get the model instance through the hash) > is there any method or any crypto algo in which is can convert > company_UUID into some string and decode back into UUID and then compare it > through icontains > There is, see Django's PasswordResetView - although you may not need it > and similarly I can do with time and age of link? > IMO, it would be easier for you to store that in a model and write the logic than encapsulate all the info in a hash > but first of all, is this the right approach? > Both get the job done, both have their own advantages, is up to you to decide in terms of benefits and costs (i.e. complexity) > or how do people in a company like slack or telegram do? > I don't know if people working there can answer that (at least shortly: https://whimsical.com/P53PjXCBWEi2fdMjP2Hti) > any kind of help will be really appreciated. > > See what am looking for certain guidance or any reference documentation. > https://docs.djangoproject.com/en/3.1/topics/auth/default/#django.contrib.auth.views.PasswordResetView https://github.com/django/django/blob/master/django/contrib/auth/views.py#L189 Hope that helps getting your way through it > -- > 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/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.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%2BFDnhLpNarCiO2H-BxwC5VsPSXqtd72sxSem8b-zCxAOfvUbQ%40mail.gmail.com.
Create an invitation link using django rest framework?
am looking for some advice/Mentorship. wanted to create an *invitation link for onboarding user to a company* similarly slack does by sending company employees email so that they could directly join the company but using the Django rest framework is there any method that you can refer? see things that I have in my mind coming is that I can put company_id in hash inside a link and then when a user will come with that hash I can compare it and onboard the user. but in that case, there is no link_time_age I can compare! is there any method or any crypto algo in which is can convert company_UUID into some string and decode back into UUID and then compare it through icontains and similarly I can do with time and age of link? but first of all, is this the right approach? or how do people in a company like slack or telegram do? any kind of help will be really appreciated. See what am looking for certain guidance or any reference documentation. -- 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/5cec683f-45d8-4259-a992-0a20f2f3053an%40googlegroups.com.
How to send mail along with update method in viewsets in Django Rest Framework?
I am working on a simple performance management system with react on frontend and django on the backend. They are supervisors who can give reviews to supervisees and supervisees can respond. I want all employees to receive email when they receive reviews from their supervisors and all the supervisors to receive email when their reviews are responded. For reviews and responses I am using two different serializers but same model. Serializer for Response is: ```python class ResponseSerializer(serializers.ModelSerializer): supervisor_name = serializers.SerializerMethodField('get_supervisor_name') supervisor_email = serializers.SerializerMethodField('get_supervisor_email') supervisee_name = serializers.SerializerMethodField('get_supervisee_name') supervisee_email = serializers.SerializerMethodField('get_supervisee_email') class Meta: model = Review fields = ( 'id', 'review_text', 'response_text', 'date_of_review', 'date_of_response', 'supervisor', 'supervisor_name', 'supervisor_email', 'supervisee', 'supervisee_name', 'supervisee_email') read_only_fields = ('review_text', 'date_of_review', 'supervisor', 'supervisee') def get_supervisor_name(self, obj): return obj.supervisor.first_name + " " + obj.supervisor.last_name def get_supervisor_email(self, obj): return obj.supervisor.email def get_supervisee_name(self, obj): return obj.supervisee.first_name + " " + obj.supervisee.last_name def get_supervisee_email(self, obj): return obj.supervisee.email ``` For sending mail I am using send_mail method from `django.core` And I am using Viewsets for Reviews and Responses. Now Response operation will always be an update operation because Response will always be used to update existing Review object in which `response_text` field will be updated. ```python class ResponseViewSet(viewsets.ModelViewSet): queryset = Review.objects.all() permission_classes = [ # permissions.IsAuthenticated, permissions.AllowAny, ] serializer_class = ResponseSerializer def update(self, request, *args, **kwargs): serializer = ResponseSerializer(data=request.data) if serializer.is_valid(): supervisor = serializer.data["supervisor_name"] supervisee = serializer.data["supervisee_name"] query = serializer.save() mail_text = "Hi {}\n\nYou got a response for your 1:1 from {}.\n\nClick below to see the response:\n\n{}".format( supervisor, supervisee, "https://example.com/#/pms/reviewsBySupervisor";, ) try: if not settings.DEFAULT_EMAIL_RECIPIENTS: settings.DEFAULT_EMAIL_RECIPIENTS.append( str(serializer.data["supervisor_email"]) ) send_mail( subject="New Response Received", message=mail_text, from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=settings.DEFAULT_EMAIL_RECIPIENTS, fail_silently=False, ) except (SMTPRecipientsRefused, SMTPSenderRefused): LOGGER.exception("There was a problem submitting the form.") return Response(serializer.data, status=status.HTTP_201_CREATED) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) ``` So, the problem that I am facing is that when I try to send mail with `update` method in ResponseViewset as shown above. I get the following error: ``` Internal Server Error: /UMS/api/responses/38/ Traceback (most recent call last): File "/home/shishir/Projects/performance_management/performance_management/reviews/serializers.py", line 77, in get_supervisor_name return obj.supervisor.first_name + " " + obj.supervisor.last_name AttributeError: 'NoneType' object has no attribute 'first_name' ``` So, what is happening is due to some reason, all the fields of that particular review are getting set to `null` as soon as I try to update and hence getting `NoneType object has no attribute`. I have checked in database table(MySQL), all the fields are getting set to null. Can anyone tell me why is this happening ? Where am I going wrong ? And what is the correct way to do it? -- 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/4af2150d-7113-407f-96c9-943ae9ee6758n%40googlegroups.com.
Re: Django Rest Framework Validation Order Issue
Hi Özgür, I'm not sure if you saw it or not but I did come up with a solution in another branch (https://github.com/epicserve/drf-validation-issue/blob/fix-validation/pizzas/serializers.py) and I did end up overriding *run_validation* and *to_internal_value*. If I can find time, I think I'll look into putting my solution into a fork of DRF and just see what might break when I run tests. It doesn't seem like anything would break, but I'm not confident that is the case. On Wednesday, July 1, 2020 at 6:02:53 AM UTC-5, Özgür Akçalı wrote: > > I think you also need to override *run_validators *method in your example > project for it to work as you expect, just like you did for > *to_internal_value. > *If a validation error is raised fom run_validators method, *validate *method > is not called, so you can not aggregate any possible errors raised from > validation checks in that method. > > Also, with this flow, you should take care not to raise validation errors > in your custom *validate *methods one by one, but aggregate them and > raise them or return them together there as well. > > On Wednesday, July 1, 2020 at 1:45:00 PM UTC+3, Özgür Akçalı wrote: >> >> Though you can not achieve what you want by just overriding *validate, *and >> not overriding *run_validation*. >> >> This would be a major change in DRF though, as with the current behavior, >> when you write your *validate *method, you can assume other validations >> passed, so I imagine changing this behavior as default now would break a >> lot of existing code. I think this would fit better as an optional >> addition, maybe with a configuration option on existing serializer classes, >> or with a different set of serializer classes. >> >> On Wednesday, July 1, 2020 at 1:59:33 AM UTC+3, Brent O'Connor wrote: >>> >>> I guess my point is that I don't feel like I should have to override >>> anything and this should be DRF's default behavior. 🙂 Thank you for >>> pointing out that `validation` should be the method that should be used. >>> >>> On Tue, Jun 30, 2020, 5:42 PM Carl Nobile wrote: >>> >>>> Brent, overriding the 'to_internal_value' method is normal and >>>> encouraged, however, the 'run_validation' shouldn't generally be >>>> overridden, what you can override is the 'validate' method which is called >>>> by 'run_validation'. >>>> ~Carl >>>> >>>> On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor >>>> wrote: >>>> >>>>> For anyone that might come across this thread, I went ahead and >>>>> created an issue >>>>> <https://github.com/encode/django-rest-framework/issues/7394> for >>>>> this on Github. >>>>> >>>>> On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: >>>>>> >>>>>> I created an example project >>>>>> <https://github.com/epicserve/drf-validation-issue> to illustrate >>>>>> this issue, but basically if you have custom validation logic on a >>>>>> serializer and the data has a field that isn't valid, then the errors >>>>>> raised are only the field level errors and not the custom validation >>>>>> logic >>>>>> errors. This ends up being a bad user experience because the user can >>>>>> fix >>>>>> the field error and then when post another request they can end up >>>>>> getting >>>>>> errors thrown in the custom validation. I'm thinking this might need to >>>>>> be >>>>>> an issue added the DRF project on Github, but thought I would check here >>>>>> first. Please see the project example for more details. >>>>>> >>>>> -- >>>>> 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/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/django-rest-framework/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com?utm_medium=e
Re: Django Rest Framework Validation Order Issue
I think you also need to override *run_validators *method in your example project for it to work as you expect, just like you did for *to_internal_value. *If a validation error is raised fom run_validators method, *validate *method is not called, so you can not aggregate any possible errors raised from validation checks in that method. Also, with this flow, you should take care not to raise validation errors in your custom *validate *methods one by one, but aggregate them and raise them or return them together there as well. On Wednesday, July 1, 2020 at 1:45:00 PM UTC+3, Özgür Akçalı wrote: > > Though you can not achieve what you want by just overriding *validate, *and > not overriding *run_validation*. > > This would be a major change in DRF though, as with the current behavior, > when you write your *validate *method, you can assume other validations > passed, so I imagine changing this behavior as default now would break a > lot of existing code. I think this would fit better as an optional > addition, maybe with a configuration option on existing serializer classes, > or with a different set of serializer classes. > > On Wednesday, July 1, 2020 at 1:59:33 AM UTC+3, Brent O'Connor wrote: >> >> I guess my point is that I don't feel like I should have to override >> anything and this should be DRF's default behavior. 🙂 Thank you for >> pointing out that `validation` should be the method that should be used. >> >> On Tue, Jun 30, 2020, 5:42 PM Carl Nobile wrote: >> >>> Brent, overriding the 'to_internal_value' method is normal and >>> encouraged, however, the 'run_validation' shouldn't generally be >>> overridden, what you can override is the 'validate' method which is called >>> by 'run_validation'. >>> ~Carl >>> >>> On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor >>> wrote: >>> >>>> For anyone that might come across this thread, I went ahead and created an >>>> issue <https://github.com/encode/django-rest-framework/issues/7394> >>>> for this on Github. >>>> >>>> On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: >>>>> >>>>> I created an example project >>>>> <https://github.com/epicserve/drf-validation-issue> to illustrate >>>>> this issue, but basically if you have custom validation logic on a >>>>> serializer and the data has a field that isn't valid, then the errors >>>>> raised are only the field level errors and not the custom validation >>>>> logic >>>>> errors. This ends up being a bad user experience because the user can fix >>>>> the field error and then when post another request they can end up >>>>> getting >>>>> errors thrown in the custom validation. I'm thinking this might need to >>>>> be >>>>> an issue added the DRF project on Github, but thought I would check here >>>>> first. Please see the project example for more details. >>>>> >>>> -- >>>> 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/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/django-rest-framework/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> >>> --- >>> Carl J. Nobile (Software Engineer) >>> carl@gmail.com >>> >>> ------- >>> >>> -- >>> 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/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%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/86b2a1e3-21cf-466a-920c-4645b8125af4o%40googlegroups.com.
Re: Django Rest Framework Validation Order Issue
Though you can not achieve what you want by just overriding *validate, *and not overriding *run_validation*. This would be a major change in DRF though, as with the current behavior, when you write your *validate *method, you can assume other validations passed, so I imagine changing this behavior as default now would break a lot of existing code. I think this would fit better as an optional addition, maybe with a configuration option on existing serializer classes, or with a different set of serializer classes. On Wednesday, July 1, 2020 at 1:59:33 AM UTC+3, Brent O'Connor wrote: > > I guess my point is that I don't feel like I should have to override > anything and this should be DRF's default behavior. 🙂 Thank you for > pointing out that `validation` should be the method that should be used. > > On Tue, Jun 30, 2020, 5:42 PM Carl Nobile > wrote: > >> Brent, overriding the 'to_internal_value' method is normal and >> encouraged, however, the 'run_validation' shouldn't generally be >> overridden, what you can override is the 'validate' method which is called >> by 'run_validation'. >> ~Carl >> >> On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor > > wrote: >> >>> For anyone that might come across this thread, I went ahead and created an >>> issue <https://github.com/encode/django-rest-framework/issues/7394> for >>> this on Github. >>> >>> On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: >>>> >>>> I created an example project >>>> <https://github.com/epicserve/drf-validation-issue> to illustrate this >>>> issue, but basically if you have custom validation logic on a serializer >>>> and the data has a field that isn't valid, then the errors raised are only >>>> the field level errors and not the custom validation logic errors. This >>>> ends up being a bad user experience because the user can fix the field >>>> error and then when post another request they can end up getting errors >>>> thrown in the custom validation. I'm thinking this might need to be an >>>> issue added the DRF project on Github, but thought I would check here >>>> first. Please see the project example for more details. >>>> >>> -- >>> 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/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> >> ------- >> Carl J. Nobile (Software Engineer) >> carl@gmail.com >> >> ------- >> >> -- >> 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/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%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/bfc354ad-f398-4380-a481-a1d1764f21f4o%40googlegroups.com.
Re: Django Rest Framework Validation Order Issue
I guess my point is that I don't feel like I should have to override anything and this should be DRF's default behavior. 🙂 Thank you for pointing out that `validation` should be the method that should be used. On Tue, Jun 30, 2020, 5:42 PM Carl Nobile wrote: > Brent, overriding the 'to_internal_value' method is normal and encouraged, > however, the 'run_validation' shouldn't generally be overridden, what you > can override is the 'validate' method which is called by 'run_validation'. > ~Carl > > On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor > wrote: > >> For anyone that might come across this thread, I went ahead and created an >> issue <https://github.com/encode/django-rest-framework/issues/7394> for >> this on Github. >> >> On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: >>> >>> I created an example project >>> <https://github.com/epicserve/drf-validation-issue> to illustrate this >>> issue, but basically if you have custom validation logic on a serializer >>> and the data has a field that isn't valid, then the errors raised are only >>> the field level errors and not the custom validation logic errors. This >>> ends up being a bad user experience because the user can fix the field >>> error and then when post another request they can end up getting errors >>> thrown in the custom validation. I'm thinking this might need to be an >>> issue added the DRF project on Github, but thought I would check here >>> first. Please see the project example for more details. >>> >> -- >> 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/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com >> <https://groups.google.com/d/msgid/django-rest-framework/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > --- > Carl J. Nobile (Software Engineer) > carl.nob...@gmail.com > > ------- > > -- > 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/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%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%2Bx7ZMp9HOprA-aUjP93s02BVLmMyz8%3DwKrGZjgA2gPAh2ExJg%40mail.gmail.com.
Re: Django Rest Framework Validation Order Issue
Brent, overriding the 'to_internal_value' method is normal and encouraged, however, the 'run_validation' shouldn't generally be overridden, what you can override is the 'validate' method which is called by 'run_validation'. ~Carl On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor wrote: > For anyone that might come across this thread, I went ahead and created an > issue <https://github.com/encode/django-rest-framework/issues/7394> for > this on Github. > > On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: >> >> I created an example project >> <https://github.com/epicserve/drf-validation-issue> to illustrate this >> issue, but basically if you have custom validation logic on a serializer >> and the data has a field that isn't valid, then the errors raised are only >> the field level errors and not the custom validation logic errors. This >> ends up being a bad user experience because the user can fix the field >> error and then when post another request they can end up getting errors >> thrown in the custom validation. I'm thinking this might need to be an >> issue added the DRF project on Github, but thought I would check here >> first. Please see the project example for more details. >> > -- > 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/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- --- Carl J. Nobile (Software Engineer) carl.nob...@gmail.com ------- -- 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/CAGQqDQL2UvWyjr6UgK%2BpCDexAc%2BC%2BeBUGxAwZYyaxC3dJYwGsQ%40mail.gmail.com.
Re: Django Rest Framework Validation Order Issue
For anyone that might come across this thread, I went ahead and created an issue <https://github.com/encode/django-rest-framework/issues/7394> for this on Github. On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: > > I created an example project > <https://github.com/epicserve/drf-validation-issue> to illustrate this > issue, but basically if you have custom validation logic on a serializer > and the data has a field that isn't valid, then the errors raised are only > the field level errors and not the custom validation logic errors. This > ends up being a bad user experience because the user can fix the field > error and then when post another request they can end up getting errors > thrown in the custom validation. I'm thinking this might need to be an > issue added the DRF project on Github, but thought I would check here > first. Please see the project example for more details. > -- 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/ea8a9b5d-a671-42b4-9cee-043f28f8efa3o%40googlegroups.com.
Re: Django Rest Framework Validation Order Issue
Carl, I created another branch <https://github.com/epicserve/drf-validation-issue/blob/fix-validation/pizzas/serializers.py> on my example project that solves this issue by overriding two DRF methods (to_internal_value and run_validation). I'm probably going to create an issue in DRF that suggests that a solution like this gets added. On Saturday, June 27, 2020 at 3:34:05 PM UTC-5, Carl Nobile wrote: > > Then write your custom validation as a field validator and put them all in > the list in the order you want them to fire off in or you could include the > field validator checks into your custom validation method. > The problem is that DRF can only implement what the common cases are, not > all the edge cases people may need, but the hooks are there in the code to > customize it the way you want. > > > On Sat, Jun 27, 2020 at 4:05 PM Brent O'Connor > wrote: > >> Unfortunately, that doesn't really solve the issue because you want >> field-level validation to run because you want to make sure that valid >> numbers, etc. are being sent to the API. >> >> On Sat, Jun 27, 2020 at 12:25 PM Carl Nobile > > wrote: >> >>> It is possible to turn off the built infield errors. The empty list >>> essentially turns off al field validation. If there are multiple and you >>> don't want all turned off you would need to specify them yourself. >>> >>> Class SomeSeializer(...): >>> >>> class Meta: >>> extra_kwargs = { >>>'field_name': {'validators': []}, >>>} >>> >>> On Fri, Jun 26, 2020 at 6:08 PM Brent O'Connor >> > wrote: >>> >>>> I created an example project >>>> <https://github.com/epicserve/drf-validation-issue> to illustrate this >>>> issue, but basically if you have custom validation logic on a serializer >>>> and the data has a field that isn't valid, then the errors raised are only >>>> the field level errors and not the custom validation logic errors. This >>>> ends up being a bad user experience because the user can fix the field >>>> error and then when post another request they can end up getting errors >>>> thrown in the custom validation. I'm thinking this might need to be an >>>> issue added the DRF project on Github, but thought I would check here >>>> first. Please see the project example for more details. >>>> >>>> -- >>>> 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/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/django-rest-framework/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> >>> --- >>> Carl J. Nobile (Software Engineer) >>> carl@gmail.com >>> >>> --- >>> >>> -- >>> 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/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%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 >&g
Re: Django Rest Framework Validation Order Issue
I understand that you can go about solving it this way, but it seems like a lot of extra work when it just works the way you would expect on a Django ModelForm. I'm guessing this isn't possible for it to "just work", so I might end up making an issue in the DRF project. On Saturday, June 27, 2020 at 3:34:05 PM UTC-5, Carl Nobile wrote: > > Then write your custom validation as a field validator and put them all in > the list in the order you want them to fire off in or you could include the > field validator checks into your custom validation method. > The problem is that DRF can only implement what the common cases are, not > all the edge cases people may need, but the hooks are there in the code to > customize it the way you want. > > > On Sat, Jun 27, 2020 at 4:05 PM Brent O'Connor > wrote: > >> Unfortunately, that doesn't really solve the issue because you want >> field-level validation to run because you want to make sure that valid >> numbers, etc. are being sent to the API. >> >> On Sat, Jun 27, 2020 at 12:25 PM Carl Nobile > > wrote: >> >>> It is possible to turn off the built infield errors. The empty list >>> essentially turns off al field validation. If there are multiple and you >>> don't want all turned off you would need to specify them yourself. >>> >>> Class SomeSeializer(...): >>> >>> class Meta: >>> extra_kwargs = { >>>'field_name': {'validators': []}, >>>} >>> >>> On Fri, Jun 26, 2020 at 6:08 PM Brent O'Connor >> > wrote: >>> >>>> I created an example project >>>> <https://github.com/epicserve/drf-validation-issue> to illustrate this >>>> issue, but basically if you have custom validation logic on a serializer >>>> and the data has a field that isn't valid, then the errors raised are only >>>> the field level errors and not the custom validation logic errors. This >>>> ends up being a bad user experience because the user can fix the field >>>> error and then when post another request they can end up getting errors >>>> thrown in the custom validation. I'm thinking this might need to be an >>>> issue added the DRF project on Github, but thought I would check here >>>> first. Please see the project example for more details. >>>> >>>> -- >>>> 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/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/django-rest-framework/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> >>> --- >>> Carl J. Nobile (Software Engineer) >>> carl@gmail.com >>> >>> --- >>> >>> -- >>> 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/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%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%2Bx
Re: Django Rest Framework Validation Order Issue
Then write your custom validation as a field validator and put them all in the list in the order you want them to fire off in or you could include the field validator checks into your custom validation method. The problem is that DRF can only implement what the common cases are, not all the edge cases people may need, but the hooks are there in the code to customize it the way you want. On Sat, Jun 27, 2020 at 4:05 PM Brent O'Connor wrote: > Unfortunately, that doesn't really solve the issue because you want > field-level validation to run because you want to make sure that valid > numbers, etc. are being sent to the API. > > On Sat, Jun 27, 2020 at 12:25 PM Carl Nobile > wrote: > >> It is possible to turn off the built infield errors. The empty list >> essentially turns off al field validation. If there are multiple and you >> don't want all turned off you would need to specify them yourself. >> >> Class SomeSeializer(...): >> >> class Meta: >> extra_kwargs = { >>'field_name': {'validators': []}, >>} >> >> On Fri, Jun 26, 2020 at 6:08 PM Brent O'Connor >> wrote: >> >>> I created an example project >>> <https://github.com/epicserve/drf-validation-issue> to illustrate this >>> issue, but basically if you have custom validation logic on a serializer >>> and the data has a field that isn't valid, then the errors raised are only >>> the field level errors and not the custom validation logic errors. This >>> ends up being a bad user experience because the user can fix the field >>> error and then when post another request they can end up getting errors >>> thrown in the custom validation. I'm thinking this might need to be an >>> issue added the DRF project on Github, but thought I would check here >>> first. Please see the project example for more details. >>> >>> -- >>> 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/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-rest-framework/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> >> ------- >> Carl J. Nobile (Software Engineer) >> carl.nob...@gmail.com >> >> --- >> >> -- >> 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/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%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%2Bx7ZMq7iMmi4PaQ9aBjGaEybKWH0piWumZTOOfR5-wJOBwwZw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CA%2Bx7ZMq7iMmi4PaQ9aBjGaEybKWH0piWumZTOOfR5-wJOBwwZw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- --- Carl J. Nobile (Software Engineer) carl.nob...@gmail.com --- -- 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/CAGQqDQLz_RockggWs3GxXkkqoMYQ%3DWL%3DZiZ-TLuta7He2BR5aA%40mail.gmail.com.
Re: Django Rest Framework Validation Order Issue
Unfortunately, that doesn't really solve the issue because you want field-level validation to run because you want to make sure that valid numbers, etc. are being sent to the API. On Sat, Jun 27, 2020 at 12:25 PM Carl Nobile wrote: > It is possible to turn off the built infield errors. The empty list > essentially turns off al field validation. If there are multiple and you > don't want all turned off you would need to specify them yourself. > > Class SomeSeializer(...): > > class Meta: > extra_kwargs = { >'field_name': {'validators': []}, >} > > On Fri, Jun 26, 2020 at 6:08 PM Brent O'Connor > wrote: > >> I created an example project >> <https://github.com/epicserve/drf-validation-issue> to illustrate this >> issue, but basically if you have custom validation logic on a serializer >> and the data has a field that isn't valid, then the errors raised are only >> the field level errors and not the custom validation logic errors. This >> ends up being a bad user experience because the user can fix the field >> error and then when post another request they can end up getting errors >> thrown in the custom validation. I'm thinking this might need to be an >> issue added the DRF project on Github, but thought I would check here >> first. Please see the project example for more details. >> >> -- >> 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/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com >> <https://groups.google.com/d/msgid/django-rest-framework/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > ------- > Carl J. Nobile (Software Engineer) > carl.nob...@gmail.com > > ------- > > -- > 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/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%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%2Bx7ZMq7iMmi4PaQ9aBjGaEybKWH0piWumZTOOfR5-wJOBwwZw%40mail.gmail.com.
Re: Django Rest Framework Validation Order Issue
It is possible to turn off the built infield errors. The empty list essentially turns off al field validation. If there are multiple and you don't want all turned off you would need to specify them yourself. Class SomeSeializer(...): class Meta: extra_kwargs = { 'field_name': {'validators': []}, } On Fri, Jun 26, 2020 at 6:08 PM Brent O'Connor wrote: > I created an example project > <https://github.com/epicserve/drf-validation-issue> to illustrate this > issue, but basically if you have custom validation logic on a serializer > and the data has a field that isn't valid, then the errors raised are only > the field level errors and not the custom validation logic errors. This > ends up being a bad user experience because the user can fix the field > error and then when post another request they can end up getting errors > thrown in the custom validation. I'm thinking this might need to be an > issue added the DRF project on Github, but thought I would check here > first. Please see the project example for more details. > > -- > 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/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- --- Carl J. Nobile (Software Engineer) carl.nob...@gmail.com ------- -- 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/CAGQqDQ%2BOzPQ-Xuad4OboE-%2BgXF_-uAkuxF%2B9XT5jLPiAnFJfog%40mail.gmail.com.
Django Rest Framework Validation Order Issue
I created an example project <https://github.com/epicserve/drf-validation-issue> to illustrate this issue, but basically if you have custom validation logic on a serializer and the data has a field that isn't valid, then the errors raised are only the field level errors and not the custom validation logic errors. This ends up being a bad user experience because the user can fix the field error and then when post another request they can end up getting errors thrown in the custom validation. I'm thinking this might need to be an issue added the DRF project on Github, but thought I would check here first. Please see the project example for more details. -- 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/121a7ebe-4b34-4197-be60-1178730361f7o%40googlegroups.com.
Re: Pytest + Django Rest Framework
Boa tarde, Fernando...Obrigado pela resposta. Já pensei em fazer isso sim, inclusive já tinha iniciado os testes através dele. Porém existem dois problemas que não consegui resolver: 1° - Ao executar o comando ``manage.py test tests/``, é como se os testes > não estivessem sendo executados, retornando o seguinte: > System check identified no issues (0 silenced). -- Ran 0 tests in 0.000s OK 2° - Através dos testes do framework é possível exportar um arquivo para um arquivo xml, para que possa ser lido pelo sonarqube, assim como faço com o pytest? Agradeço desde já pela ajuda. Em quarta-feira, 27 de maio de 2020 13:45:40 UTC-3, Fernando Augusto Rodrigues de araujo escreveu: > > Fala João, você já pensou em usar a própria api de testes do Django e do > Django Rest Framework ? > > Com isso você consegue testar facilmente as suas querys se forem através > do próprio ORM do Django, te dando assim uma cobertura maior do código. > > Em relação aos testes unitários com o banco de dados, quando você utilizar > a api do Django, ele cria um banco de teste para fazer isto e é muito > rápido. > > Em terça-feira, 26 de maio de 2020 21:16:57 UTC-3, João Batista escreveu: >> >> Olá, estou iniciando os testes unitários da minha aplicação e é a >> primeira vez que faço os testes em uma aplicação. >> Eu possuo dois apps no projeto, e já consigo fazer os testes do meu >> arquivo "functions" utilizando o pytest e verificando a cobertura através >> do sonarqube. Porém, a cobertura ainda é baixa, pois dentro da view da >> aplicação possui muitas linhas de query's... >> >> Aqui começa o meu problema, como eu faria para executar os testes nessa >> parte do código, uma vez que fui instruído a executar os testes unitários >> de forma isolada? Eu pensei em criar um mock, e até descobri que o próprio >> pytest consegue criar o objeto para não se comunicar com o banco que está >> em produção, porém não consegui aplicar. >> >> pois quando tento acessar a elementos da aplicação recebo a seguinte >> resposta quando executo o pytest: >> ``django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.``, >> alguma solução pra isso ou método mais simples de executar os testes dentro >> das views? >> >> Agradeço a atenção de todos. >> > -- 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/2113c5fd-ccf7-4d99-b187-ebc81269830b%40googlegroups.com.
Re: Pytest + Django Rest Framework
Fala João, você já pensou em usar a própria api de testes do Django e do Django Rest Framework ? Com isso você consegue testar facilmente as suas querys se forem através do próprio ORM do Django, te dando assim uma cobertura maior do código. Em relação aos testes unitários com o banco de dados, quando você utilizar a api do Django, ele cria um banco de teste para fazer isto e é muito rápido. Em terça-feira, 26 de maio de 2020 21:16:57 UTC-3, João Batista escreveu: > > Olá, estou iniciando os testes unitários da minha aplicação e é a primeira > vez que faço os testes em uma aplicação. > Eu possuo dois apps no projeto, e já consigo fazer os testes do meu > arquivo "functions" utilizando o pytest e verificando a cobertura através > do sonarqube. Porém, a cobertura ainda é baixa, pois dentro da view da > aplicação possui muitas linhas de query's... > > Aqui começa o meu problema, como eu faria para executar os testes nessa > parte do código, uma vez que fui instruído a executar os testes unitários > de forma isolada? Eu pensei em criar um mock, e até descobri que o próprio > pytest consegue criar o objeto para não se comunicar com o banco que está > em produção, porém não consegui aplicar. > > pois quando tento acessar a elementos da aplicação recebo a seguinte > resposta quando executo o pytest: > ``django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.``, > alguma solução pra isso ou método mais simples de executar os testes dentro > das views? > > Agradeço a atenção de todos. > -- 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/f1bfe64b-0ae9-4b14-ba8a-8d2ae63093cd%40googlegroups.com.
Pytest + Django Rest Framework
Olá, estou iniciando os testes unitários da minha aplicação e é a primeira vez que faço os testes em uma aplicação. Eu possuo dois apps no projeto, e já consigo fazer os testes do meu arquivo "functions" utilizando o pytest e verificando a cobertura através do sonarqube. Porém, a cobertura ainda é baixa, pois dentro da view da aplicação possui muitas linhas de query's... Aqui começa o meu problema, como eu faria para executar os testes nessa parte do código, uma vez que fui instruído a executar os testes unitários de forma isolada? Eu pensei em criar um mock, e até descobri que o próprio pytest consegue criar o objeto para não se comunicar com o banco que está em produção, porém não consegui aplicar. pois quando tento acessar a elementos da aplicação recebo a seguinte resposta quando executo o pytest: ``django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.``, alguma solução pra isso ou método mais simples de executar os testes dentro das views? Agradeço a atenção de todos. -- 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/915f6f08-f3fb-4d59-a09a-9878a82cfd85%40googlegroups.com.
Re: Behaviour driven development in Django rest framework.
I realize that this is just my opinion, however, I've been writing code for over 40 years and Python for over 20. There is nothing, no process, not a special package that will develop good code for you, only well-trained engineers that follow best practices. In Python, this means the coding standard PEP-8. Also, read read read RFCs they are how things are supposed to work. The next time I see credentials in the body of a request I will scream or for that matter versioning done like this /api/v1/, use mimetypes, please. If you are doing RESTful web services and you have not read Roy Fielding's dissertation and understood it don't write RESTful web services. Never give developers with five years or less experience a huge project to do, it WILL be done poorly guaranteed. If you must use Agile then the software architect needs to completely decide upfront how the system will work in detail, or once again it won't work. If you're not doing this then get out of the business. Small teams under 8 or 9 don't need Agile just a very good lead. Too much structure makes for bad engineers. They trust daddy too much and will never think for themselves. With too little structure they will surf the web all day and not write a line of code. OK, Nuff said. ~Carl On Sun, May 3, 2020 at 4:09 AM Tom Victor wrote: > My current company is planing to switch to behaviour driven development > also known as BDD. After a long google search I came to the conclusion that > behave is the semi official python package for BDD in python. I am > wondering how could we practically use along with drf. > > What is the correct ideal way to > > 1. Structure our test files. > 2. Where should we keep the BDD feature, step files? > 3. Which category would add fall under, unit testing, integration testing > or acceptance testing? > > Thanks > > Ref : https://behave.readthedocs.io/en/latest/ > > -- > 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/a24833b2-823f-4867-86c5-09d3943a4a85%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/a24833b2-823f-4867-86c5-09d3943a4a85%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- --- Carl J. Nobile (Software Engineer) carl.nob...@gmail.com ------- -- 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/CAGQqDQK_KKhrpYN26fXkZKRqGqn5RF%2B%3DYhfy22fzSGVgXtGz5w%40mail.gmail.com.
Behaviour driven development in Django rest framework.
My current company is planing to switch to behaviour driven development also known as BDD. After a long google search I came to the conclusion that behave is the semi official python package for BDD in python. I am wondering how could we practically use along with drf. What is the correct ideal way to 1. Structure our test files. 2. Where should we keep the BDD feature, step files? 3. Which category would add fall under, unit testing, integration testing or acceptance testing? Thanks Ref : https://behave.readthedocs.io/en/latest/ -- 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/a24833b2-823f-4867-86c5-09d3943a4a85%40googlegroups.com.
Re: Connect to MongoDB Atlas using Django Rest Framework
It is easy and you can use pymongo to do that. Hope it helps. I usually dont use ORM for NoSQL because mongo has some amazing feature that will be lost if using conventional ORM. On Monday, April 27, 2020 at 4:57:09 AM UTC+8, Lawrence Thanakumar wrote: > > Hello All, > > I am building a movie review webpage as a project using Angular and Django > Rest Framework. I want to connect to MongoDB Atlas or MongoDB, but I am not > getting a proper resource online to configure it in latest django version. > Please help me by providing steps for configuring the mongoDB in django > rest framework. > > Thanks > Lawrence > -- 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/0d5f5439-29f6-453d-8280-09462630f2d7%40googlegroups.com.
Connect to MongoDB Atlas using Django Rest Framework
Hello All, I am building a movie review webpage as a project using Angular and Django Rest Framework. I want to connect to MongoDB Atlas or MongoDB, but I am not getting a proper resource online to configure it in latest django version. Please help me by providing steps for configuring the mongoDB in django rest framework. Thanks Lawrence -- 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/dd02b3c4-2eb9-4451-83b8-3549c59f0f00%40googlegroups.com.
How do I create an API endpoint with django rest framework jwt for when user is logged_in?
I am trying to create an endpoint for when a user is logged in to check the status of user is logged in react js. For my backend, I use django rest-framework. Here is the backend code. serializers.py: from rest_framework import serializers from rest_framework_jwt.settings import api_settings from django.contrib.auth.models import User class UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('username',) # handle signups only class UserSerializerWithToken(serializers.ModelSerializer): token = serializers.SerializerMethodField() password = serializers.CharField(write_only=True) def get_token(self, obj): jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER payload = jwt_payload_handler(obj) token = jwt_encode_handler(payload) return token def create(self, validated_data): password = validated_data.pop('password', None) inst = self.Meta.model(**validated_data) if password is not None: inst.set_password(password) inst.save() return inst class Meta: fields = ('token', 'username', 'password') urls.py: The following code is where I would create the endpoint from django.contrib import adminfrom django.urls import path, includefrom django.conf import settingsfrom django.conf.urls.static import staticfrom rest_framework_jwt.views import obtain_jwt_tokenfrom rest_framework_jwt.views import verify_jwt_token urlpatterns = [ path('api-auth/', include('rest_framework.urls')), # path('rest-auth/', include('rest_auth.urls')), # path('rest-auth/registration/', include('rest_auth.registration.urls')), path('token-auth/', obtain_jwt_token), path('api-token-verify/', verify_jwt_token), path('login/', include('login.urls')), path('admin/', admin.site.urls), path('api/', include('menus.api.urls')), path('phlogapi/', include('phlogfeeder.phlogapi.urls'))] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) I am confused on how to create a endpoint with jwt. -- 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/9327e4b4-cfa8-4209-bb2a-435fa74b080a%40googlegroups.com.
Re: How to upload multiple image files in django rest framework?
This might help you. https://blog.rousek.name/2017/08/11/uploading-multiple-files-in-django-admin/ Mark On Tue, Apr 14, 2020 at 11:23 AM Talha Amjad wrote: > I am making a e-commerce like web application where users can upload > advertisements and add multiple images to the advertisement. I can upload > only one image but i want users to have the ability to add many images. Is > there any way? > > #Here is my model > class AdImage(models.Model): > advertisement = models.ForeignKey(Advertisement, on_delete > = models.CASCADE) > image = models.ImageField(upload_to='media/', null= True, blank=True) > > #here is my serializer > class AdImageSerializer(serializers.ModelSerializer): > > class Meta: > model = AdImage > fields = "__all__" > > #here is my viewset > class AdImageViewset(ModelViewSet): > queryset = AdImage.objects.all() > serializer_class = AdImageSerializer > parser_classes = (MultiPartParser, FormParser,) > > -- > 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/44329f35-b810-4413-a35e-d6514c009a80%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/44329f35-b810-4413-a35e-d6514c009a80%40googlegroups.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/CAEqej2Mb-yB2h6jR5KZ8wptaBG9y07da1bKQ8%3D-mkQ3jy%2B6tAQ%40mail.gmail.com.
How to upload multiple image files in django rest framework?
I am making a e-commerce like web application where users can upload advertisements and add multiple images to the advertisement. I can upload only one image but i want users to have the ability to add many images. Is there any way? #Here is my model class AdImage(models.Model): advertisement = models.ForeignKey(Advertisement, on_delete = models.CASCADE) image = models.ImageField(upload_to='media/', null= True, blank=True) #here is my serializer class AdImageSerializer(serializers.ModelSerializer): class Meta: model = AdImage fields = "__all__" #here is my viewset class AdImageViewset(ModelViewSet): queryset = AdImage.objects.all() serializer_class = AdImageSerializer parser_classes = (MultiPartParser, FormParser,) -- 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/44329f35-b810-4413-a35e-d6514c009a80%40googlegroups.com.
Re: Android + Django rest framework
>From your app, you have to make API calls to the rest endpoints. Using some android library to make http requests from your app. Then you will receive json in your Android app. Just make a Google search , there are tons of posts El mar., 25 feb. 2020 15:01, Zain Mehar escribió: > please anyone tell me how i can connect my Django rest API with Android > mobile application > > -- > 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/3e49dbb5-0471-4e9d-8206-a8acd6fa5641%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/3e49dbb5-0471-4e9d-8206-a8acd6fa5641%40googlegroups.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/CANyTv7qcg%2BZt4UqXA2whqRXTThavmexLUjJnE%3DWSZAPpF5RADw%40mail.gmail.com.
Android + Django rest framework
please anyone tell me how i can connect my Django rest API with Android mobile application -- 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/3e49dbb5-0471-4e9d-8206-a8acd6fa5641%40googlegroups.com.
Re: Retrieving Unrelated Objects in Django REST Framework
If they are both O2O relations, why do not you make another model where you store the three id's? If not I guess you can just access the same way you access Application from Offer. something like: offer.application.contract , I mean if you can find application, just acces the contract via dot notation El lun., 20 ene. 2020 a las 22:13, Foobar () escribió: > My model consists of 3 classes: Offer, Application, and Contract. > > > Relationships are as follows: > > (1) Application to Offer: One to One > > (2) Application to Contract: One to One > > > Is there a way for me to access Contract from Offer via Application in a > single REST call? I know how to access Application from Offer since they > are related. A way around this is to relate Offer to Contract but I would > prefer not to do this because it would not be considered good relational > database design. > > Any help would be greatly appreciated. Thanks. > > -- > 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/68a53b1a-9ac8-41f9-856f-26f54046e35e%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/68a53b1a-9ac8-41f9-856f-26f54046e35e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- ---- Gonzalo Amadio -- 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/CANyTv7oGojOp_Er6SwC9tZ0ONCDgbhF0BTCD4ThDs4kk6GK7%2Bw%40mail.gmail.com.
Retrieving Unrelated Objects in Django REST Framework
My model consists of 3 classes: Offer, Application, and Contract. Relationships are as follows: (1) Application to Offer: One to One (2) Application to Contract: One to One Is there a way for me to access Contract from Offer via Application in a single REST call? I know how to access Application from Offer since they are related. A way around this is to relate Offer to Contract but I would prefer not to do this because it would not be considered good relational database design. Any help would be greatly appreciated. Thanks. -- 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/68a53b1a-9ac8-41f9-856f-26f54046e35e%40googlegroups.com.
Django Rest Framework Nested Serializer does not work.
Hello. How are you? I have met second problem in DRF. #view.py class TestView(viewsets.ViewSet): def test(self, request): serializer = UserInfoSerializer(request.user) return Response(serializer.data) #serializers.py class PrivateIDInfoSerializer(serializers.ModelSerializer): class Meta: model = Private_ID_Info fields = ('first_name', 'last_name', ) class UserInfoSerializer(serializers.ModelSerializer): privateIdInfo = PrivateIDInfoSerializer(many=True, read_only=True) class Meta: model = User fields = ('id', 'username', 'email', 'role', 'privateIdInfo', ) #models.py class Private_ID_Info(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) photo = models.ImageField(blank=False, null=False) title = models.CharField(max_length=5, choices=TitleChoices.choices(), default=TitleChoices.MR.value) first_name = models.CharField(max_length=20, blank=True) class Meta: managed = True db_table = 'private_id_info' The result of response is only results of users table. I want results of Private_ID_Info table also. Please help me. Thank you. -- 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/a19b748d-9cb9-4dc8-a0ae-a554abb8c8ab%40googlegroups.com.
Re: How to create django-rest-framework without authentication
In the settings you have t configure no authentication. Here you have a reference: https://stackoverflow.com/questions/27085219/how-can-i-disable-authentication-in-django-rest-framework El mar., 29 oct. 2019 23:48, Sajan s escribió: > Hi All, > > i am creating my new API using django-rest-framework. we have Open API > will do all authentication. new API doesn't required any authentication. > > Is it possible to create API without authentication and Table > > Thanks & Regards, > Sajan > > -- > 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/269412e5-1794-4e46-b981-b2d025736e19%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/269412e5-1794-4e46-b981-b2d025736e19%40googlegroups.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/CANyTv7piGAYHoBqTM4d2GoHMfQBLzXMSHRPUhkGPCCmOo89cXw%40mail.gmail.com.
How to create django-rest-framework without authentication
Hi All, i am creating my new API using django-rest-framework. we have Open API will do all authentication. new API doesn't required any authentication. Is it possible to create API without authentication and Table Thanks & Regards, Sajan -- 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/269412e5-1794-4e46-b981-b2d025736e19%40googlegroups.com.
Re: New package: django-rest-framework-features
Thanks for this, will look at it. On Fri, Oct 25, 2019, 12:54 AM balintb wrote: > Hello there, > > I've created a shiny new package, for naming the schema endpoints, and > doing awesome stuff with that information. > > You can find the medium article > <https://medium.com/@cloudcode.bbb/how-to-build-your-django-rest-framework-api-based-on-named-features-97432ce07969?sk=3b056da82cc849181250ecf29518f4be>, > the docs > <https://django-rest-framework-features.readthedocs.io/en/latest/> and > the source > <https://github.com/cloudcode-hungary/django-rest-framework-features/> at > these links. Can't wait to see the responses, I'll create a pull request > tomorrow for being a third party package as mentioned here > <https://www.django-rest-framework.org/community/third-party-packages/>. > > -- > 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/bad56865-8d48-4b9e-8c10-7a44863998ac%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/bad56865-8d48-4b9e-8c10-7a44863998ac%40googlegroups.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/CACvaL4B3j8rchav3WBEYf7ek6z8Y0uw%3D862BncUGEgGB6tPnpA%40mail.gmail.com.
New package: django-rest-framework-features
Hello there, I've created a shiny new package, for naming the schema endpoints, and doing awesome stuff with that information. You can find the medium article <https://medium.com/@cloudcode.bbb/how-to-build-your-django-rest-framework-api-based-on-named-features-97432ce07969?sk=3b056da82cc849181250ecf29518f4be>, the docs <https://django-rest-framework-features.readthedocs.io/en/latest/> and the source <https://github.com/cloudcode-hungary/django-rest-framework-features/> at these links. Can't wait to see the responses, I'll create a pull request tomorrow for being a third party package as mentioned here <https://www.django-rest-framework.org/community/third-party-packages/>. -- 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/bad56865-8d48-4b9e-8c10-7a44863998ac%40googlegroups.com.
Re: Does Django REST framework supports django 3 alpha release ?
I think (but need to check) that DRF’s master branch is already compatible with Django 3.0a1. Before Django 3.0 is released Django REST Framework will have a compatible release available. (The current “preview” period is precisely for this purpose.) > On 1 Oct 2019, at 07:42, PK P. wrote: > > > Does Django REST framework supports django 3 alpha release ? > What is the timeline of REST framework for django 3 ? > > https://docs.djangoproject.com/en/3.0/releases/3.0/ > <https://docs.djangoproject.com/en/3.0/releases/3.0/> > https://code.djangoproject.com/wiki/Version3.0Roadmap > <https://code.djangoproject.com/wiki/Version3.0Roadmap> > > -- > 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 > <mailto:django-rest-framework+unsubscr...@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/c150b151-4534-4442-99a6-f6e551a5c860%40googlegroups.com > > <https://groups.google.com/d/msgid/django-rest-framework/c150b151-4534-4442-99a6-f6e551a5c860%40googlegroups.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/3CC80753-ADDA-46E5-9FE5-8997B982D0D7%40gmail.com.
Does Django REST framework supports django 3 alpha release ?
Does Django REST framework supports django 3 alpha release ? What is the timeline of REST framework for django 3 ? https://docs.djangoproject.com/en/3.0/releases/3.0/ https://code.djangoproject.com/wiki/Version3.0Roadmap -- 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/c150b151-4534-4442-99a6-f6e551a5c860%40googlegroups.com.
Re: How to log request and response for 4XX Http status in Django Rest Framework?
You could have a look at drf-tracking. You can find it here: https://github.com/aschn/drf-tracking <https://github.com/aschn/drf-tracking>. Thomas > On 21 Aug 2019, at 13:01, kumar deepak wrote: > > The default behaviour of DRF is to throw exception for 5XX, but return valid > response with error details for 4XX. > > I want to log request and response of any API call which fails with 4XX. > > > > Currently the log only shows Bad Request : /path/api/ > > > -- > 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 > <mailto:django-rest-framework+unsubscr...@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/a22b8cae-4179-4c6c-9085-2cbb40ce5efe%40googlegroups.com > > <https://groups.google.com/d/msgid/django-rest-framework/a22b8cae-4179-4c6c-9085-2cbb40ce5efe%40googlegroups.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/1A8E9232-CA16-420E-A242-8D7D2AEFE7E0%40me.com.
How to log request and response for 4XX Http status in Django Rest Framework?
The default behaviour of DRF is to throw exception for 5XX, but return valid response with error details for 4XX. I want to log request and response of any API call which fails with 4XX. Currently the log only shows Bad Request : /path/api/ -- 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/a22b8cae-4179-4c6c-9085-2cbb40ce5efe%40googlegroups.com.
Django-rest-framework specific authentication backend
I have been trying to find a related topic but there seems to be none. Please point me to it if it has been suggested before. In my Django application I have 3 types of login backend. User login backend, admin login backend and api login backend. All persist login attempts on the backend. It is important then to choose the right login backend immediately. To circumvent this problem I had to implement my own authentication method. def authenticate(request=None, **credentials): > """ > If the given credentials are valid, return a User object. > """ > backend = ModelBackend() > backend_path = settings.REST_FRAMEWORK_AUTH_BACKEND > try: > user = _authenticate_with_backend(backend, backend_path, request, > credentials) > except PermissionDenied: > # This backend says to stop in our tracks - this user should not be > allowed in at all. > user_login_failed.send(sender=__name__, > credentials=_clean_credentials(credentials), request=request) > return > if user is None: > user_login_failed.send(sender=__name__, > credentials=_clean_credentials(credentials), request=request) > return > # Annotate the user object with the path of the backend. > user.backend = backend_path > return user > > It's more or less a copy paste of what is in django/contrib/auth/__init__.py What are your thoughts? -- 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/0d8ce352-a798-4b77-bc53-67947b82623e%40googlegroups.com.
logo usage for course picture to show people about that is related to Django Rest Framework
I really love django rest framework and I want to make a course where i can teach people how to use Django Rest Framework and i want to use django rest framework's logo in my course cover picture. because i need to engage attention. can i use it? -- 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/ee0cc064-d3ba-42b6-90d7-7a4a708ed7f2%40googlegroups.com.
Django REST framework 3.10 released!
The 3.10 release, with OpenAPI schema generation, is now available on PyPI: https://www.django-rest-framework.org/community/3.10-announcement/ Please to chime in on the issues if you've any problems with the new OpenAPI functionality - we'll aim to address any remaning niggles there as quickly as possible. As always, thanks so much to all our sponsors, contributors, and users for helping keep things rolling! All the best, T. -- 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/df8d0d49-6ede-45b5-b0f5-f98746008d48%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to filter queryset for serializing a nested serializer using instance in django rest framework?
My serializers.py file: from rest_framework import serializers from diagnosisApp.models import Question, Option class OptionSerializer(serializers.ModelSerializer): class Meta: model = Option fields = ('id', 'content') class QuestionSerializer(serializers.Serializer): content = serializers.CharField() options = OptionSerializer( Option.objects.filter(optiongroup__question=**insert instance value here**).distinct(), many=True ) I'm trying to create a nested OptionSerializer inside QuestionSerializer but I need to filter the queryset based on the question instance which will be passed during initialization in this section: `optiongroup__question=**insert instance value here**`. How do I do this? P.S: Please don't tell me to use ModelSerializer or SerializerMethodField because options is not directly related to Question and the options field needs to be writable. -- 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/11b7939f-caef-420d-bcd3-21b4f56d80f0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
"'MongoClient' object is not iterable" in Django Rest Framework
Hello Guys, I am trying to learn DRF and so that I have started one sample project in Django Rest. And For that project, I want to use MongoDB in DRF so I have setup mongoengine in it. But I have been facing this following error when I try to run it. raise TypeError("'MongoClient' object is not iterable") TypeError: 'MongoClient' object is not iterable I have tried so many solutions from the internet but I have not found any useful solution. If anyone has any idea then please help. Thanks in Advance. -- 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/776f30f0-fbc3-4c2e-8ccf-c3d1514e3319%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. from django.contrib.auth.models import User, Group from rest_framework import serializers from rest_framework_mongoengine import serializers class ToolSerializer(serializers.DocumentSerializer): class Meta: model = Tool fields = '__all__'from django.db import models # Create your models here. from mongoengine import Document, EmbeddedDocument, fields class Tool(Document): label = fields.StringField(required=True) description = fields.StringField(required=True, null=True) inputs = fields.ListField(fields.EmbeddedDocumentField(ToolInput)) class ToolInput(EmbeddedDocument): name = fields.StringField(required=True) value = fields.DynamicField(required=True) """ Django settings for mr_note project. Generated by 'django-admin startproject' using Django 2.0.3. For more information on this file, see https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.0/ref/settings/ """ import os import mongoengine # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'dlbv9%!1!hoia=k+hbtv-sckvu%cpntid&o5q1*+(%t^a_64p+' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'mr_note.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'mr_note.wsgi.application' # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } DATABASES = mongoengine.connect( db="mr_note_dev", host="localhost" ) # DATABASES = mongoengine.connect( # db="tools", # host="localhost" # ) # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValid
Django REST Framework v3.9.3
Django REST Framework v3.9.3 is now available on PyPI. This will be the last version of Django REST Framework to support Python 2, so if you're on that, update now. -- 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.
Re: getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
tion_test >> >> def update(self, instance, validated_data): >> instance.title = validated_data.get("title", instance.title) >> instance.type = validated_data.get("type", instance.type) >> instance.category = validated_data.get("category", instance.category) >> instance.admin = validated_data.get("admin", instance.admin) >> >> for question in self.questions: >> q = QuestionSerializer(instance=question["id"], data=question) >> q.is_valid(raise_exception=True) >> q.save() >> >> if self.new_questions: >> new_questions = self.new_questions.save() >> for question in new_questions: >> question.save() >> return instance >> >> >> On Mon, Apr 8, 2019 at 3:08 PM Arbaz Hundekar < >> arbaz.hunde...@avetoconsulting.com> wrote: >> >>> try this >>> questions = self.context['request'].data.get("questions",None) >>> >>> If questions is not in request.data it will be set to None. It will work >>> with your not condition as well. >>> >>> On Mon, Apr 8, 2019 at 6:35 PM zohaib younis >>> wrote: >>> >>>> arbaz thanks for your guidance i have resolved that issue now when i >>>> try to create a test it is giving me an error >>>> for question in data["questions"]: >>>> keyError :'questions' >>>> can you help me with that problem thanks >>>> >>>> On Mon, Apr 8, 2019 at 3:00 PM Arbaz Hundekar < >>>> arbaz.hunde...@avetoconsulting.com> wrote: >>>> >>>>> while instantiating your serializer do like this ser = >>>>> Serializer(context={"request": request}) >>>>> >>>>> On Mon, Apr 8, 2019 at 1:57 PM zohaib younis >>>>> wrote: >>>>> >>>>>> def validate(self, data, *args, **kwargs): >>>>>> questions = self.context['request'].data.get("questions") >>>>>> if not questions: >>>>>> raise serializers.ValidationError("questions are required") >>>>>> if self.context["request"].method == "POST": >>>>>> self.questions = QuestionSerializer(data=questions, many=True) >>>>>> self.questions.is_valid(raise_exception=True) >>>>>> elif self.context["request"].method == "PUT": >>>>>> self.questions = questions >>>>>> self.new_questions = self.context["request"].data.get( >>>>>> "new_questions") >>>>>> if self.new_questions: >>>>>> self.new_questions = QuestionSerializer( >>>>>> data=self.new_questions, many=True) >>>>>> self.new_questions.is_valid(raise_exception=True) >>>>>> return data >>>>>> >>>>>> def create(self, data): >>>>>> evaluation_test = EvaluationTest() >>>>>> evaluation_test.category = data['category'] >>>>>> evaluation_test.admin = data['admin'] >>>>>> evaluation_test.title = data['title'] >>>>>> evaluation_test.type = data['type'] >>>>>> evaluation_test.save() >>>>>> >>>>>> for question in data['questions']: >>>>>> question.evaluationtest = evaluation_test >>>>>> question.save() >>>>>> return evaluation_test >>>>>> >>>>>> def update(self, instance, validated_data): >>>>>> instance.title = validated_data.get["title", instance.title] >>>>>> instance.type = validated_data.get["type", instance.type] >>>>>> instance.category = validated_data.get["category", instance.category] >>>>>> instance.admin = validated_data.get["admin", instance.admin] >>>>>> >>>>>> for question in self.questions: >>>>>> q = QuestionSerializer(instance=question["id"], data=question) >>>>>> q.is_valid(raise_exception=True) >>>>>> q.save() >>>>>> >>>>>> if self.new_questions: >>>>>> new_questions = self.new_questions.save() >>>>>> for question in new_questions: >>>>>> question.save() >>>>>> return instance >>>>>> >>>>>> -- >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> -- >>>>> Warm Regards, >>>>> >>>>> Arbaz >>>>> >>>>> -- >>>>> 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. >>>> >>> >>> >>> -- >>> Warm Regards, >>> >>> Arbaz >>> >>> -- >>> 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. > -- 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.
Re: getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
ns: > question.save() > return instance > > > On Mon, Apr 8, 2019 at 3:08 PM Arbaz Hundekar < > arbaz.hunde...@avetoconsulting.com> wrote: > >> try this >> questions = self.context['request'].data.get("questions",None) >> >> If questions is not in request.data it will be set to None. It will work >> with your not condition as well. >> >> On Mon, Apr 8, 2019 at 6:35 PM zohaib younis >> wrote: >> >>> arbaz thanks for your guidance i have resolved that issue now when i try >>> to create a test it is giving me an error >>> for question in data["questions"]: >>> keyError :'questions' >>> can you help me with that problem thanks >>> >>> On Mon, Apr 8, 2019 at 3:00 PM Arbaz Hundekar < >>> arbaz.hunde...@avetoconsulting.com> wrote: >>> >>>> while instantiating your serializer do like this ser = >>>> Serializer(context={"request": request}) >>>> >>>> On Mon, Apr 8, 2019 at 1:57 PM zohaib younis >>>> wrote: >>>> >>>>> def validate(self, data, *args, **kwargs): >>>>> questions = self.context['request'].data.get("questions") >>>>> if not questions: >>>>> raise serializers.ValidationError("questions are required") >>>>> if self.context["request"].method == "POST": >>>>> self.questions = QuestionSerializer(data=questions, many=True) >>>>> self.questions.is_valid(raise_exception=True) >>>>> elif self.context["request"].method == "PUT": >>>>> self.questions = questions >>>>> self.new_questions = self.context["request"].data.get( >>>>> "new_questions") >>>>> if self.new_questions: >>>>> self.new_questions = QuestionSerializer( >>>>> data=self.new_questions, many=True) >>>>> self.new_questions.is_valid(raise_exception=True) >>>>> return data >>>>> >>>>> def create(self, data): >>>>> evaluation_test = EvaluationTest() >>>>> evaluation_test.category = data['category'] >>>>> evaluation_test.admin = data['admin'] >>>>> evaluation_test.title = data['title'] >>>>> evaluation_test.type = data['type'] >>>>> evaluation_test.save() >>>>> >>>>> for question in data['questions']: >>>>> question.evaluationtest = evaluation_test >>>>> question.save() >>>>> return evaluation_test >>>>> >>>>> def update(self, instance, validated_data): >>>>> instance.title = validated_data.get["title", instance.title] >>>>> instance.type = validated_data.get["type", instance.type] >>>>> instance.category = validated_data.get["category", instance.category] >>>>> instance.admin = validated_data.get["admin", instance.admin] >>>>> >>>>> for question in self.questions: >>>>> q = QuestionSerializer(instance=question["id"], data=question) >>>>> q.is_valid(raise_exception=True) >>>>> q.save() >>>>> >>>>> if self.new_questions: >>>>> new_questions = self.new_questions.save() >>>>> for question in new_questions: >>>>> question.save() >>>>> return instance >>>>> >>>>> -- >>>>> 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. >>>>> >>>> >>>> >>>> -- >>>> Warm Regards, >>>> >>>> Arbaz >>>> >>>> -- >>>> 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. >>> >> >> >> -- >> Warm Regards, >> >> Arbaz >> >> -- >> 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.
Re: getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
n Mon, Apr 8, 2019 at 3:00 PM Arbaz Hundekar < >> arbaz.hunde...@avetoconsulting.com> wrote: >> >>> while instantiating your serializer do like this ser = >>> Serializer(context={"request": request}) >>> >>> On Mon, Apr 8, 2019 at 1:57 PM zohaib younis >>> wrote: >>> >>>> def validate(self, data, *args, **kwargs): >>>> questions = self.context['request'].data.get("questions") >>>> if not questions: >>>> raise serializers.ValidationError("questions are required") >>>> if self.context["request"].method == "POST": >>>> self.questions = QuestionSerializer(data=questions, many=True) >>>> self.questions.is_valid(raise_exception=True) >>>> elif self.context["request"].method == "PUT": >>>> self.questions = questions >>>> self.new_questions = self.context["request"].data.get( >>>> "new_questions") >>>> if self.new_questions: >>>> self.new_questions = QuestionSerializer( >>>> data=self.new_questions, many=True) >>>> self.new_questions.is_valid(raise_exception=True) >>>> return data >>>> >>>> def create(self, data): >>>> evaluation_test = EvaluationTest() >>>> evaluation_test.category = data['category'] >>>> evaluation_test.admin = data['admin'] >>>> evaluation_test.title = data['title'] >>>> evaluation_test.type = data['type'] >>>> evaluation_test.save() >>>> >>>> for question in data['questions']: >>>> question.evaluationtest = evaluation_test >>>> question.save() >>>> return evaluation_test >>>> >>>> def update(self, instance, validated_data): >>>> instance.title = validated_data.get["title", instance.title] >>>> instance.type = validated_data.get["type", instance.type] >>>> instance.category = validated_data.get["category", instance.category] >>>> instance.admin = validated_data.get["admin", instance.admin] >>>> >>>> for question in self.questions: >>>> q = QuestionSerializer(instance=question["id"], data=question) >>>> q.is_valid(raise_exception=True) >>>> q.save() >>>> >>>> if self.new_questions: >>>> new_questions = self.new_questions.save() >>>> for question in new_questions: >>>> question.save() >>>> return instance >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> -- >>> Warm Regards, >>> >>> Arbaz >>> >>> -- >>> 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. >> > > > -- > Warm Regards, > > Arbaz > > -- > 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.
Re: getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
try this questions = self.context['request'].data.get("questions",None) If questions is not in request.data it will be set to None. It will work with your not condition as well. On Mon, Apr 8, 2019 at 6:35 PM zohaib younis wrote: > arbaz thanks for your guidance i have resolved that issue now when i try > to create a test it is giving me an error > for question in data["questions"]: > keyError :'questions' > can you help me with that problem thanks > > On Mon, Apr 8, 2019 at 3:00 PM Arbaz Hundekar < > arbaz.hunde...@avetoconsulting.com> wrote: > >> while instantiating your serializer do like this ser = >> Serializer(context={"request": request}) >> >> On Mon, Apr 8, 2019 at 1:57 PM zohaib younis >> wrote: >> >>> def validate(self, data, *args, **kwargs): >>> questions = self.context['request'].data.get("questions") >>> if not questions: >>> raise serializers.ValidationError("questions are required") >>> if self.context["request"].method == "POST": >>> self.questions = QuestionSerializer(data=questions, many=True) >>> self.questions.is_valid(raise_exception=True) >>> elif self.context["request"].method == "PUT": >>> self.questions = questions >>> self.new_questions = self.context["request"].data.get( >>> "new_questions") >>> if self.new_questions: >>> self.new_questions = QuestionSerializer( >>> data=self.new_questions, many=True) >>> self.new_questions.is_valid(raise_exception=True) >>> return data >>> >>> def create(self, data): >>> evaluation_test = EvaluationTest() >>> evaluation_test.category = data['category'] >>> evaluation_test.admin = data['admin'] >>> evaluation_test.title = data['title'] >>> evaluation_test.type = data['type'] >>> evaluation_test.save() >>> >>> for question in data['questions']: >>> question.evaluationtest = evaluation_test >>> question.save() >>> return evaluation_test >>> >>> def update(self, instance, validated_data): >>> instance.title = validated_data.get["title", instance.title] >>> instance.type = validated_data.get["type", instance.type] >>> instance.category = validated_data.get["category", instance.category] >>> instance.admin = validated_data.get["admin", instance.admin] >>> >>> for question in self.questions: >>> q = QuestionSerializer(instance=question["id"], data=question) >>> q.is_valid(raise_exception=True) >>> q.save() >>> >>> if self.new_questions: >>> new_questions = self.new_questions.save() >>> for question in new_questions: >>> question.save() >>> return instance >>> >>> -- >>> 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. >>> >> >> >> -- >> Warm Regards, >> >> Arbaz >> >> -- >> 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. > -- Warm Regards, Arbaz -- 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.
Re: getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
arbaz thanks for your guidance i have resolved that issue now when i try to create a test it is giving me an error for question in data["questions"]: keyError :'questions' can you help me with that problem thanks On Mon, Apr 8, 2019 at 3:00 PM Arbaz Hundekar < arbaz.hunde...@avetoconsulting.com> wrote: > while instantiating your serializer do like this ser = > Serializer(context={"request": request}) > > On Mon, Apr 8, 2019 at 1:57 PM zohaib younis > wrote: > >> def validate(self, data, *args, **kwargs): >> questions = self.context['request'].data.get("questions") >> if not questions: >> raise serializers.ValidationError("questions are required") >> if self.context["request"].method == "POST": >> self.questions = QuestionSerializer(data=questions, many=True) >> self.questions.is_valid(raise_exception=True) >> elif self.context["request"].method == "PUT": >> self.questions = questions >> self.new_questions = self.context["request"].data.get( >> "new_questions") >> if self.new_questions: >> self.new_questions = QuestionSerializer( >> data=self.new_questions, many=True) >> self.new_questions.is_valid(raise_exception=True) >> return data >> >> def create(self, data): >> evaluation_test = EvaluationTest() >> evaluation_test.category = data['category'] >> evaluation_test.admin = data['admin'] >> evaluation_test.title = data['title'] >> evaluation_test.type = data['type'] >> evaluation_test.save() >> >> for question in data['questions']: >> question.evaluationtest = evaluation_test >> question.save() >> return evaluation_test >> >> def update(self, instance, validated_data): >> instance.title = validated_data.get["title", instance.title] >> instance.type = validated_data.get["type", instance.type] >> instance.category = validated_data.get["category", instance.category] >> instance.admin = validated_data.get["admin", instance.admin] >> >> for question in self.questions: >> q = QuestionSerializer(instance=question["id"], data=question) >> q.is_valid(raise_exception=True) >> q.save() >> >> if self.new_questions: >> new_questions = self.new_questions.save() >> for question in new_questions: >> question.save() >> return instance >> >> -- >> 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. >> > > > -- > Warm Regards, > > Arbaz > > -- > 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.
Re: getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
while instantiating your serializer do like this ser = Serializer(context={"request": request}) On Mon, Apr 8, 2019 at 1:57 PM zohaib younis wrote: > def validate(self, data, *args, **kwargs): > questions = self.context['request'].data.get("questions") > if not questions: > raise serializers.ValidationError("questions are required") > if self.context["request"].method == "POST": > self.questions = QuestionSerializer(data=questions, many=True) > self.questions.is_valid(raise_exception=True) > elif self.context["request"].method == "PUT": > self.questions = questions > self.new_questions = self.context["request"].data.get( > "new_questions") > if self.new_questions: > self.new_questions = QuestionSerializer( > data=self.new_questions, many=True) > self.new_questions.is_valid(raise_exception=True) > return data > > def create(self, data): > evaluation_test = EvaluationTest() > evaluation_test.category = data['category'] > evaluation_test.admin = data['admin'] > evaluation_test.title = data['title'] > evaluation_test.type = data['type'] > evaluation_test.save() > > for question in data['questions']: > question.evaluationtest = evaluation_test > question.save() > return evaluation_test > > def update(self, instance, validated_data): > instance.title = validated_data.get["title", instance.title] > instance.type = validated_data.get["type", instance.type] > instance.category = validated_data.get["category", instance.category] > instance.admin = validated_data.get["admin", instance.admin] > > for question in self.questions: > q = QuestionSerializer(instance=question["id"], data=question) > q.is_valid(raise_exception=True) > q.save() > > if self.new_questions: > new_questions = self.new_questions.save() > for question in new_questions: > question.save() > return instance > > -- > 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. > -- Warm Regards, Arbaz -- 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.
getting keyError: 'request' i am getting this error when i am to create an evaluation test i am newbie to django rest framework can somebody help me why i am getting this error
def validate(self, data, *args, **kwargs): questions = self.context['request'].data.get("questions") if not questions: raise serializers.ValidationError("questions are required") if self.context["request"].method == "POST": self.questions = QuestionSerializer(data=questions, many=True) self.questions.is_valid(raise_exception=True) elif self.context["request"].method == "PUT": self.questions = questions self.new_questions = self.context["request"].data.get( "new_questions") if self.new_questions: self.new_questions = QuestionSerializer( data=self.new_questions, many=True) self.new_questions.is_valid(raise_exception=True) return data def create(self, data): evaluation_test = EvaluationTest() evaluation_test.category = data['category'] evaluation_test.admin = data['admin'] evaluation_test.title = data['title'] evaluation_test.type = data['type'] evaluation_test.save() for question in data['questions']: question.evaluationtest = evaluation_test question.save() return evaluation_test def update(self, instance, validated_data): instance.title = validated_data.get["title", instance.title] instance.type = validated_data.get["type", instance.type] instance.category = validated_data.get["category", instance.category] instance.admin = validated_data.get["admin", instance.admin] for question in self.questions: q = QuestionSerializer(instance=question["id"], data=question) q.is_valid(raise_exception=True) q.save() if self.new_questions: new_questions = self.new_questions.save() for question in new_questions: question.save() return instance -- 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.