There may be a problem with your solution, as the name of the bacon is not unique. So, if you filter out the name of the sala, expecting to find one and only one sala, this may not happen.
I advise you to do:
if sala in beer.salas_set.all():
else:
this beer.salas_set.all()will return a QuerySet in which you can check if a particular object exists with the keyword "in".
source
share