[Fixed]-Django: using multiple models in one view

1๐Ÿ‘

    guest = get_object_or_404(Guest, pk=pk)
    # The 404 will catch any bad requests
    orders = Order.objects.filter(guest = guest, is_paid=False)
    context = {'form': form}
    context['orders'] = orders

remember to add it to your context and you can access it in the template

๐Ÿ‘คAdam Donaghy

0๐Ÿ‘

you could get the Orders via the foreign key, by default (if not set via related_name):

guest.order_set.objects

Good luck!

๐Ÿ‘คNhan Hoang

0๐Ÿ‘

I think you need to query Order instance from given Guest check this my help you:
orders = Order.objects.filter(guest=guest).all()
this will retrieve list of orders that you want

๐Ÿ‘คShehab ElDin

Leave a comment