Help to implement join query in django orm

2022-07-21 Thread Avi shah
I have two tables
Tbl 1
&
Tbl 2

I need to connect the two tables using a join


Thanks and regards,
Avi shah

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa7AFNmoep5MT3MwoYn1ZF0S%3DENPUdVAO-_3EmVyAzCub_Jkg%40mail.gmail.com.


Re: problems with forms.py in django

2022-07-21 Thread Mihir Patel
I will send it to you tomorrow, right now, unable to access laptop so,
sorry btw thanx for the help., I will send to you views.py tomorrow.

On Thu, 21 Jul, 2022, 11:22 pm Lakshyaraj Dash, <
dashlakshyaraj2...@gmail.com> wrote:

> I'm asking for the source code of your project. You can send it personally
> at dashlakshyaraj...@gmail.com
>
> On Thu, 21 Jul, 2022, 23:17 Mihir Patel,  wrote:
>
>> It is an inbuilt file which comes during installation in
>> django.contrib.auth- forms.py, try to replace this file in your existing
>> django folder by taking backup your old forms.py, let me know if you
>> having any problem, i am using vscode for development purpose, it shows me
>> 162 errors in terminal when i open this forms.py, i am also unable to
>> authenticate user by right credentials due to these errors.
>>
>> On Thu, 21 Jul, 2022, 11:13 pm Lakshyaraj Dash, <
>> dashlakshyaraj2...@gmail.com> wrote:
>>
>>> Please share your authentication code / your project's source code with
>>> me at
>>> dashlakshyaraj2...@gmail.com. I'll not share your code with anyone
>>> else.
>>> Trust me
>>>
>>> Thanks & Regards
>>> Lakshyaraj Dash
>>>
>>> On Thu, 21 Jul, 2022, 22:44 Mihir Patel, 
>>> wrote:
>>>
 i am using vscode for webdevelopment, i am having lot of errors in
 built in contrib.auth- forms,  i am unable to authenticate normal user also
 after signup, kindley plz help with this issue., i have attached screenshot
 in the conversation.

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/a37f203d-1e41-49c0-9932-a809621dfb7cn%40googlegroups.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAF7qQgBu7YyD7_MKgx-Vr7s%2Bi_XdE4RuzOb0xskczzk6Y5aHDA%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAC10kRFRQePUdxQN8dUUrJ3rdhBq2CQA3%2BzYgP6KcQB7jFc-4Q%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/CdSTxy1-7Yw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAF7qQgB9ChDL7aQ_z_wHRMGy5uVurDmb6c8SbzyKv28ChS15Dg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC10kRGmxPxp3AM%2BGs%3DZWZ4yMwwnDOAFGN3m1MaF2iAYH6dyow%40mail.gmail.com.


Re: problems with forms.py in django

2022-07-21 Thread Lakshyaraj Dash
I'm asking for the source code of your project. You can send it personally
at dashlakshyaraj...@gmail.com

On Thu, 21 Jul, 2022, 23:17 Mihir Patel,  wrote:

> It is an inbuilt file which comes during installation in
> django.contrib.auth- forms.py, try to replace this file in your existing
> django folder by taking backup your old forms.py, let me know if you
> having any problem, i am using vscode for development purpose, it shows me
> 162 errors in terminal when i open this forms.py, i am also unable to
> authenticate user by right credentials due to these errors.
>
> On Thu, 21 Jul, 2022, 11:13 pm Lakshyaraj Dash, <
> dashlakshyaraj2...@gmail.com> wrote:
>
>> Please share your authentication code / your project's source code with
>> me at
>> dashlakshyaraj2...@gmail.com. I'll not share your code with anyone else.
>> Trust me
>>
>> Thanks & Regards
>> Lakshyaraj Dash
>>
>> On Thu, 21 Jul, 2022, 22:44 Mihir Patel, 
>> wrote:
>>
>>> i am using vscode for webdevelopment, i am having lot of errors in built
>>> in contrib.auth- forms,  i am unable to authenticate normal user also after
>>> signup, kindley plz help with this issue., i have attached screenshot in
>>> the conversation.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/a37f203d-1e41-49c0-9932-a809621dfb7cn%40googlegroups.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAF7qQgBu7YyD7_MKgx-Vr7s%2Bi_XdE4RuzOb0xskczzk6Y5aHDA%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAC10kRFRQePUdxQN8dUUrJ3rdhBq2CQA3%2BzYgP6KcQB7jFc-4Q%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF7qQgB9ChDL7aQ_z_wHRMGy5uVurDmb6c8SbzyKv28ChS15Dg%40mail.gmail.com.


Re: problems with forms.py in django

2022-07-21 Thread Mihir Patel
It is an inbuilt file which comes during installation in
django.contrib.auth- forms.py, try to replace this file in your existing
django folder by taking backup your old forms.py, let me know if you
having any problem, i am using vscode for development purpose, it shows me
162 errors in terminal when i open this forms.py, i am also unable to
authenticate user by right credentials due to these errors.

On Thu, 21 Jul, 2022, 11:13 pm Lakshyaraj Dash, <
dashlakshyaraj2...@gmail.com> wrote:

> Please share your authentication code / your project's source code with me
> at
> dashlakshyaraj2...@gmail.com. I'll not share your code with anyone else.
> Trust me
>
> Thanks & Regards
> Lakshyaraj Dash
>
> On Thu, 21 Jul, 2022, 22:44 Mihir Patel,  wrote:
>
>> i am using vscode for webdevelopment, i am having lot of errors in built
>> in contrib.auth- forms,  i am unable to authenticate normal user also after
>> signup, kindley plz help with this issue., i have attached screenshot in
>> the conversation.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/a37f203d-1e41-49c0-9932-a809621dfb7cn%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAF7qQgBu7YyD7_MKgx-Vr7s%2Bi_XdE4RuzOb0xskczzk6Y5aHDA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC10kRFRQePUdxQN8dUUrJ3rdhBq2CQA3%2BzYgP6KcQB7jFc-4Q%40mail.gmail.com.
import unicodedata

from django import forms
from django.contrib.auth import authenticate, get_user_model, password_validation
from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX, identify_hasher
from django.contrib.auth.models import User
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import ValidationError
from django.core.mail import EmailMultiAlternatives
from django.template import loader
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from django.utils.text import capfirst
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _

UserModel = get_user_model()


def _unicode_ci_compare(s1, s2):
"""
Perform case-insensitive comparison of two identifiers, using the
recommended algorithm from Unicode Technical Report 36, section
2.11.2(B)(2).
"""
return (
unicodedata.normalize("NFKC", s1).casefold()
== unicodedata.normalize("NFKC", s2).casefold()
)


class ReadOnlyPasswordHashWidget(forms.Widget):
template_name = "auth/widgets/read_only_password_hash.html"
read_only = True

def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
summary = []
if not value or value.startswith(UNUSABLE_PASSWORD_PREFIX):
summary.append({"label": gettext("No password set.")})
else:
try:
hasher = identify_hasher(value)
except ValueError:
summary.append(
{
"label": gettext(
"Invalid password format or unknown hashing algorithm."
)
}
)
else:
for key, value_ in hasher.safe_summary(value).items():
summary.append({"label": gettext(key), "value": value_})
context["summary"] = summary
return context

def id_for_label(self, id_):
return None


class ReadOnlyPasswordHashField(forms.Field):
widget = ReadOnlyPasswordHashWidget

def __init__(self, *args, **kwargs):
kwargs.setdefault("required", False)
kwargs.setdefault("disabled", True)
super().__init__(*args, **kwargs)


class UsernameField(forms.CharField):
def to_python(self, value):
retur

Re: problems with forms.py in django

2022-07-21 Thread Lakshyaraj Dash
Please share your authentication code / your project's source code with me
at
dashlakshyaraj2...@gmail.com. I'll not share your code with anyone else.
Trust me

Thanks & Regards
Lakshyaraj Dash

On Thu, 21 Jul, 2022, 22:44 Mihir Patel,  wrote:

> i am using vscode for webdevelopment, i am having lot of errors in built
> in contrib.auth- forms,  i am unable to authenticate normal user also after
> signup, kindley plz help with this issue., i have attached screenshot in
> the conversation.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a37f203d-1e41-49c0-9932-a809621dfb7cn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF7qQgBu7YyD7_MKgx-Vr7s%2Bi_XdE4RuzOb0xskczzk6Y5aHDA%40mail.gmail.com.


Re: Hiring experienced Python + Django engineer

2022-07-21 Thread DJANGO DEVELOPER
Hi Mathew!
I have just applied on the provided email. would love to work with an
interesting team of professionals.

On Thu, Jul 21, 2022 at 10:14 PM Matthew Sherman 
wrote:

> Hi folks! My company, Clarity (claritytuition.com) is looking to fill a
> Senior Software Engineer role. We are building a financial aid platform to
> simplify the process of applying and obtaining financial aid for families,
> as well as provide tools for schools to think more like the businesses that
> they are.
>
> Our team size has gone from 0 to 15 in the past 9 months. We are seeing
> some explosive growth and are hoping to find another technical partner to
> join the journey with us. The team is awesome, work culture is chill, we
> pay well, and care about each other. It's super fulfilling, genuinely.
>
> We have two open positions. If you're interested in chatting, we are too!
> jobs.claritytuition.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1ce18235-3ebc-4ae6-8521-b7bb7f865d1an%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKPY9pmQVFpAWV5%2BBBRyKtXdEo2-yWVvyW8SdPsvKK_9pLtm%3DA%40mail.gmail.com.


Hiring experienced Python + Django engineer

2022-07-21 Thread Matthew Sherman
Hi folks! My company, Clarity (claritytuition.com) is looking to fill a 
Senior Software Engineer role. We are building a financial aid platform to 
simplify the process of applying and obtaining financial aid for families, 
as well as provide tools for schools to think more like the businesses that 
they are.

Our team size has gone from 0 to 15 in the past 9 months. We are seeing 
some explosive growth and are hoping to find another technical partner to 
join the journey with us. The team is awesome, work culture is chill, we 
pay well, and care about each other. It's super fulfilling, genuinely. 

We have two open positions. If you're interested in chatting, we are too!
jobs.claritytuition.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1ce18235-3ebc-4ae6-8521-b7bb7f865d1an%40googlegroups.com.


Re: Role based Authentication

2022-07-21 Thread Mihir Patel
i am unable to authenticate normal user, can anyone help me?, when i try to 
normal user login in, it show's me same login page after putting right 
credentials, when i checked built in authenticationform in django folder in 
vscode it show's me 162 errors in terminal, can anyone help, what problem 
could be?, i have attached forms.py where i am getting an errors.

On Thursday, July 8, 2021 at 12:03:38 PM UTC+5:30 abubak...@gmail.com wrote:

> can you please give me a example? so that I can understand it well. thanks 
> in advance.
>
>
> 
>  Virus-free. 
> www.avast.com 
> 
>  
> <#m_-4885092898279415690_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Thu, Jul 8, 2021 at 9:57 AM Avi shah  wrote:
>
>> you can normally do it using fbv's , just make sure while saving the 
>> model , you also save the user model also parallely with the student 
>> model(in reference with my repo) 
>>
>> On Thu, Jul 8, 2021 at 7:44 AM DJANGO DEVELOPER  
>> wrote:
>>
>>> Avi Shah I have just visited your github repo. is there any other code 
>>> where you have performed multi-user sign up with FBV's?
>>>
>>> On Thu, Jul 8, 2021 at 4:53 AM sum abiut  wrote:
>>>
 From the admin site you can create different groups and then assign 
 specific users to specific groups. 
 then  filter users' roles based on the specific group that you have 
 assigned them to.



 On Thu, Jul 8, 2021 at 3:53 AM Lalit Suthar  
 wrote:

> you can extend User model and have a role field in default User model
>
> https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html
>
> On Wed, 7 Jul 2021 at 20:47, Avi shah  wrote:
>
>> https://github.com/Avishah123/Multi-user-auth1
>>
>> On Wed, Jul 7, 2021 at 8:16 PM DJANGO DEVELOPER  
>> wrote:
>>
>>> f
>>>
>>> On Wed, Jul 7, 2021 at 7:07 PM LokRaj Kumar Vuppu <
>>> lokrajku...@gmail.com> wrote:
>>>
 How to assign a role to user when registered into our application. 

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, 
 send an email to django-users...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/21f87894-278b-4705-83cb-9a426ea85ee7n%40googlegroups.com
  
 
 .

>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, 
>>> send an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAKPY9pn6SGzjAsfTpoMJPeXBn0XSyNcW-ko8rJ%2BUH-WksRr-oA%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google 
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CALa7AFOCSQ-cr1pkBTVzDmZvH7b2%3DEb7TPcjHK%2BkhaonuwL%2BRQ%40mail.gmail.com
>>  
>> 
>> .
>>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAGp2JVEvTHTGsdFbrk5w_b%2B_h9T4u0rnL4R-Zr2TWBt12PyhYA%40mail.gmail.com
>  
> 
> .
>


 -- 

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users.

Re: problem

2022-07-21 Thread Lakshyaraj Dash
There's a info attr to messages but the the thing is in the syntax. He has
another curve bracket inside his messages syntax

On Thu, 21 Jul, 2022, 08:59 Abdul Qoyyuum, 
wrote:

> Maybe print your "messages" and confirm if there's no "info" attribute or
> method to it.
>
> On Wed, Jul 20, 2022 at 11:12 PM chaouch elhem 
> wrote:
>
>> [image: image_2022-07-20_133032905.png]
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/02625cc0-2c42-476c-8505-8a9df707b910n%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Abdul Qoyyuum Bin Haji Abdul Kadir
> HP No: +673 720 8043
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA3DN%3DVNbav0N05fKj%3D1mYoNFCZ%2Bukr9QBJhtnWa8HG3122icw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF7qQgCCkAC4Ydeo2WRqCsN5QgcQG91qd_2VDfGx315C-vdV9g%40mail.gmail.com.


Re: How to use Authentication in DRF

2022-07-21 Thread Ammar Mohammed
How is your login view working ?
Or this is your login view ?

Please share the whole app views and urls.

(I suggest using DRF class based views as it's alot useful and helpful when
it comes to authentication and permissions)

Regards,

--
Ammar Mohammed
On 21 Jul 2022 08:24, "Salima Begum"  wrote:

> Thanks  Ammar Mohammed for the quick response, After login to the
> website  through Chrome browser, I got the response.
>  But when I run from Postman to test API by mentioning Basic AUTH
> credentials of which I created user models login credentials it's giving
> home page html response but which I want is JSON Response. Why it's not
> reading credentials I mentioned there?
>
> Thanks
> ~Salima
>
>
> On Thu, Jul 21, 2022 at 10:58 AM Ammar Mohammed 
> wrote:
>
>> Hey Salima
>> I guess you can use access token authentication in DRF.
>> But Do you recive the response without logging in?
>> Please explain more please
>>
>> --
>>
>> Ammar Mohammed
>> +249 113075979
>> On 21 Jul 2022 07:08, "Salima Begum" 
>> wrote:
>>
>>> Hi all,
>>>
>>> I am trying to convert my current project(It is developed in Django) to
>>> DRF. So, I set up DRF into my project then I wrote an endpoint for after
>>> user login on the session I need to get the response when I test the
>>> my-reviews API.
>>>
>>> models.py
>>> ```
>>> class customer(models.Model):
>>> cust_id = models.IntegerField(null="true")
>>> email = models.CharField(max_length=100)
>>> # reemail = models.CharField(max_length=100, null='true')
>>> password = models.CharField(max_length=500)
>>> repassword = models.CharField(max_length=500, null='true')
>>> firstname = models.CharField(max_length=225)
>>> lastname = models.CharField(max_length=225, null=True)
>>> state = models.CharField(max_length=64, null=True)
>>> city = models.CharField(max_length=64, null=True)
>>> location = models.CharField(max_length=225, null=True)
>>> Zip = models.CharField(max_length=64)
>>> mailing = models.CharField(max_length=1000)
>>> added_date = models.DateTimeField(editable=False)
>>> modified_date = models.DateTimeField(null=True, blank=True)
>>> last_loggedin = models.DateField()
>>> ```
>>> views.py
>>>
>>> ```
>>> @api_view(['GET'])
>>> def myservicereviewAPI(request):
>>> # If a user session is logged out it will redirect to the home page.
>>> if ((request.session.get('email') is None) or
>>> (request.session.get('email') == "")):
>>> # redirecting user after logged out to home page.
>>> return HttpResponseRedirect("/home")
>>> if request.method == 'GET':
>>> students = services_review.objects.all().order_by('-added_date')
>>> serializer = ServicesReviewSerializer(students, many=True)
>>> return Response(serializer.data)
>>> ```
>>> urls.py
>>> ```
>>> path('myservicereviewAPI', views.myservicereviewAPI,
>>> name='myservicereviewAPI'),
>>> ```
>>>
>>> Results of Postman when I run 'myservicereviewAPI'
>>>
>>> After login Browser results of 'myservicereviewAPI'
>>>
>>> Please Help me to achieve this.
>>>
>>> Thanks
>>> ~Salima
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/CAMSz6bk%2B73gVaO0Pfq3BfT4msHAprSwyxcCq
>>> -9BWtS-faT%3DYAA%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/CAHs1H7vv1b5zYXTNAk-Pm9FU5r9wVCJjODi9Pmc6BCaykKRnu
>> Q%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAMSz6b%3D6HpkhJGpr5yf64GL8fta10DgfPKs
> botKNVETh_d8mPA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receivin

Re: Need help on reducing cognitive complexity

2022-07-21 Thread Michael Thomas
Personally I think the code has a very weird "smell"... Assuming you don't
have any way of rewriting the calling code and are stuck with editing this
single method, I'd suggest something along the lines of:

@staticmethod
def in_circle_check(obj_type, item, uuid):
if obj_type not in ['trees', 'flowers']:
return None

# trim the trailing 's', so this can be used elsewhere...
obj_type = obj_type[:-1]

if not (plant := get_plant_with_circles(uuid)):
return None

if plant[f'in_all_{obj_type}_types']:
return True

circle_objects = plant[f'{obj_type}_circle']['items']

if isinstance(circle_objects, list):
if not isinstance(item, (list, tuple)):
items = item
else:
items = [item]

if all([i in circle_objects for i in items]):
return True

return -1


On Thu, Jul 21, 2022 at 1:19 PM Shaheed Haque 
wrote:

> The first step is to ensure you have a precise and accurate understanding
> of the code before optimization. Right now, I am suspicious of at least 2
> things in the code.
>
> First, the function returns any of {None, -1, True}. While this is
> certainly allowed, is this correct? If not, please correct the code. If so,
> then can you explain the rule that governs the return type (assuming it is
> not literally what is written).
>
> Second, as your previous respond ant hinted, the first 2 lines look like
> an optimisation attempt, except for the return type issue. Can you clarify
> if the purpose of these lines is optimisation, or not?
>
>
>
>
> On Thu, 21 Jul 2022, 06:53 Sencer Hamarat, 
> wrote:
>
>> Hi everyone,
>>
>> I have a code block with high cognitive complexity below:
>>
>> @staticmethod
>> def in_circle_check(obj_type, item, uuid, item_is_array=False):
>>
>> if obj_type not in ['trees', 'flowers']:
>> return None
>>
>> plant = get_plant_with_circles(uuid)
>> if not plant:
>> return None
>>
>> if obj_type == 'trees':
>> if plant['in_all_tree_types']:
>> return True
>> circle_objects = plant['tree_circle']['items']
>> else:
>> if plant['in_all_flower_types']:
>> return True
>> circle_objects = plant['flower_circle']['items']
>>
>> if isinstance(circle_objects, list):
>> if item_is_array:
>> for item in item:
>> if item not in circle_objects:
>> return -1
>> return True
>> else:
>> if item in circle_objects:
>> return True
>> else:
>> return -1
>>
>> return -1
>>
>>
>> I try to move the first 3 if statements on the beginning of the block
>> into new methods but that maneuver ends up with raising complexity.
>>
>> Can anybody help me to learn how to reduce cognitive complexity in code
>> blocks like this?
>>
>> Kind regards,
>> Sencer HAMARAT
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACp8TZhBa9EbekcT1ApmzdDRVk2vCb64%3DvvXHrSawO2RJSySpQ%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHAc2jewMaP41PJZN8OVFqZ2hw41A9r8c8DDjRJc0VG%3DqP9X5g%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEdx1fpaLC4C4Lo%3DXW6-vqb4_Mk7RLOh5qa9254cKkmMEZ5obw%40mail.gmail.com.