[Fixed]-Django queries: OR operator, should return only one record

1👍

.get should be used to retrieve a single record, as you noticed. Use filter otherwise:

data = Recording.objects.filter(Q(name='xyz') | Q(name="default")).first()

If which one matters, use order_by to arrange the order.

You could also use:

data = Recording.objects.filter(Q(name='xyz') | Q(name="default"))[0]

Which is practically the same. For more information see Django docs.

👤Wtower

Leave a comment