Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ingredient images #1001

Conversation

olijzenga
Copy link
Contributor

@olijzenga olijzenga commented Apr 5, 2022

Based on #653

Proposed Changes

  • Added ingredient image url to the search response in the same way that it is done for exercises.
  • Added a script for downloading images from OFF for ingredients which are used in nutrition plans.

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • (Only updated the test for the case that the ingredient does not have an image.)
  • Added yourself to AUTHORS.rst

Other questions

  • Do users need to run some commands in their local instances due to this PR
    (e.g. database migration)?
    No

@olijzenga
Copy link
Contributor Author

Note: setting up the database schema on this branch using a clean database gave me a migration conflict error. I worked around it by making a new migration using manage.py makemigration --migrate. However I did not include this migration in the pull request because I thought I might be doing something wrong (not much Django experience here). Let me know if I should include it.

@rolandgeider
Copy link
Member

You are right, there is a migration missing, feel free to commit it

@olijzenga
Copy link
Contributor Author

Done

@@ -167,11 +169,22 @@ def search(request):
)

for ingredient in ingredients:
if hasattr(ingredient, 'image'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just do if ingredient.image: here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this but in that case RelatedObjectDoesNotExist is raised when the image is not there. The recommended way by Django to work around this is by using hasattr (according to https://docs.djangoproject.com/en/4.0/topics/db/examples/one_to_one/).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right

@rolandgeider
Copy link
Member

Thanks for the PR! still need to do some things before merging to master, but I think the backend is done

@rolandgeider rolandgeider merged commit 7960d09 into wger-project:feature/ingredient-images Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants