Please respond please

as u see i fetch the products from database to a template using for loop now if the user click buy how to get the info of the bought book in the views ?

Jksnl,

The code you shared is not really python. It looks like HTML with a loop made in some tool that could underneath be expanded into python or could be JavaScript or almost anything.

The entire code seems to display something just once and I do not see you sharing any code that gets data from a database, or that adds anything to the database or that checks the database to see if anything has changed or fetches the changes.

If you were writing much of this in python that could be read by us and included more, people could possibly help.

As it is, it sounds like you need to have some kind of loop construct around your code that looks perhaps a bit like this pseudocode:

  • optionally show current order status

  • LOOP till done

    • Accept an input from the user who is ordering something.
    • Update the database
    • Show the current orders.
    • Continue till the user is done
  • Finalize

If your design is a bit different, fine. You may need to find out how your work environment asks to put up a new web page and many other things and perhaps ask more specific questions here or perhaps wherever your work environment is normally discussed.

thank you do much for replaying… yes you are right i should have post something more but yeah i am working on django… this is my code to show the products which are books on my database and this is photo how it looks now if i click buy and this is the models code how to get the info to my views ? i just want if the user clicks buy then the book attribute( aka category and name sent to views) i learnt in the past if i have a text field which has a name"text" then in views i can have a variable x=request.post.get(" text) then i assign this x or print it but now the situation is different

i cant post many photos once this is how page looks

and these are models

Thank you for posting the view that reponds to the submit button. Copy-pasting the code - enclosed in triple backticks to preserve the formatting - would be even better. Also I personally find text on a black background less readable.
At the end of your view, you let it rerender the page, but there’s no information about the user’s actions coming with it.

The way you have things set up, you might expand the query Books.objects.all() with a reverse lookup of the foreign key from Buyer to Book and comparing it with the current user to see which books were already selected.
Although you would also need some way to determine if it’s a purchase made in the current session.

THANKS could u please send me a short code to see what do you mean exactly ? just a code to put in views to know which book is selected… thanks in advance

according to this

you can find the Buyers for a Book by doing

buyers = Book().buyer_set.all()

in this case you will probably want

books_bought = Books.buyer_set.filter( name=username)

This may not be the best solution but if you add this query to the response you can check in your template (the html) whether a book should be grayed out or not

I don’t know how to do that but you could also do that with the border-style:

border_style : {% if i in books.bought %} "dashed" {% else %} "solid" {% endif %}

again thank you for your response… i learn something new but in my case what should i do if i dont have class buyer just want to get books info after clicking buy ? what shoul i do un views?