How to collect data from model into select tag

General Tech Technology & Software 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

Model.py

class techgroup(models.Model):
    Technology=models.CharField(max_length=50)

    def __str__(self):
       return self.Technology

views.py

def technology(request,id,*args, **kwargs):
    Technology = techgroup.objects.all()
    print(Technology)
    selected_item = get_object_or_404(techgroup, 
                   pk=request.POST.get('Technology_id'))
    # get the user you want (connect for example) in the var "user"
    techgroup.Technology = selected_item
    techgroup.save()
    context = {'Technology': Technology}
    return render(request, "analytics/radio.html", context)

url.py

path('technology//', views.technology, name='technology'),

What is wrong in this code? I'm getting the following error

technology() missing 1 required positional argument: 'id'

profilepic.png
manpreet 2 years ago

This question doesn't have anything to do with your title.

Your view is expecting an argument called id. But your URL is providing one called pk. These need to match. Change the URL:

path('technology/id>/', ...)

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.