[Answer]-Django 1.6: ValueError invalid literal for int() with base 10

1πŸ‘

βœ…

I think you should do this in your views.py:

def doclistings(request):
    d = getVariables(request)
    s_name = request.session.get('selection')  # Change variable name
    d['userselection'] = s_name  # Update this for new variable name s_name
    spec = Specialization.objects.get(name=s_name)  # Get spec object
    # Now this should work:
    doctors = Doctor.objects.filter(specialization = spec).order_by('-likes')  
    paginator = Paginator(doctors, 20) #Show 20 doctors per page
    page =  page = request.GET.get('page')

 try:....

As @Rohan said you could also do:

def doclistings(request):
    d = getVariables(request)
    s_name = request.session.get('selection')  # Change variable name
    d['userselection'] = s_name  # Update this for new variable name s_name
    # Now this should work:
    doctors = Doctor.objects.filter(specialization__name = s_name).order_by('-likes')  
    paginator = Paginator(doctors, 20) #Show 20 doctors per page
    page =  page = request.GET.get('page')

 try:....

In the second way you don’t need to get the specialization object, you use specialization__name to say to Django that gets the doctors wich foreign key to specialization has the name equals to s_name.

Leave a comment