'str' object has no attribute 'objects'

Yametazamwa mara 886
Ruka hadi kwenye ujumbe wa kwanza ambao haujasomwa

Chetan Rokade

hayajasomwa,
28 Des 2019, 06:00:5328/12/2019
kwa Django users
Hi Friends,
Getting below error while doing search operation :
'str' object has no attribute 'objects'

Code:
1) html having search button :
<form method="POST" action="SearchCR">
        {% csrf_token %}
        <div class="form-group">
            <div class="col-lg-5">
                <input type="text" name="CR_NAME" class="form-control" placeholder="Enter Application">
            </div>
            <label class="col-lg-2">
                <button type="submit" class="btn btn-primary"> Search </button>
            </label>
        </div>
    </form>


Chetan Rokade

hayajasomwa,
28 Des 2019, 06:02:4828/12/2019
kwa Django users
2) views.py :
def SearchCR(request):
    if request.method == "POST":
        CR = request.POST['CR_NAME']

        if CR:
            match = CR.objects.filter(Q(App_Name__icontains=CR) |
                                      Q(CR_Status__icontains=CR)
                                      )
            if match:
                return render(request, 'changes/changes.html', {'CR': match})
            else:
                messages.error(request, 'No result found')

        else:
            return redirect('changes')

    return render(request, 'changes/changes.html')

gaurav jain

hayajasomwa,
28 Des 2019, 06:11:3128/12/2019
kwa django...@googlegroups.com
Show the backend code of the post request 
Regards
Gaurav Jain

--
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/80817360-1f88-4980-a628-89f6ee24b1d3%40googlegroups.com.

Suraj Thapa FC

hayajasomwa,
28 Des 2019, 06:19:4728/12/2019
kwa django...@googlegroups.com
Cr is string not a model that's why this error is coming...
change the name of cr variable in which you are taking the request data 

Chetan Rokade

hayajasomwa,
28 Des 2019, 06:33:5328/12/2019
kwa Django users
This is resolved now. I had used variable name same as class name. 

Regards,
Chetan


On Saturday, December 28, 2019 at 4:30:53 PM UTC+5:30, Chetan Rokade wrote:

Chetan Rokade

hayajasomwa,
28 Des 2019, 06:44:1428/12/2019
kwa django...@googlegroups.com
Thanks Suraj Thapa. 


Sent from Yahoo Mail for iPhone
Chetan
                <button type=" submit" class="btn btn- primary"> Search </button>
            </label>
        </div>
    </form>


--
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
Jibu wote
Mjibu mchapishaji
Sambaza
Ujumbe 0 mpya