Skip to content

Commit

Permalink
Fix #53 Add code in AddRecipeView to save user uploaded images
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-townsend committed Dec 13, 2022
1 parent bbdd7d3 commit 09f9c79
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kitchentales/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@

STATIC_URL = '/static/'
STATICFILES_STORAGE = 'cloudinary_storage.storage.StaticHashedCloudinaryStorage'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_URL = '/media/'
Expand Down
1 change: 1 addition & 0 deletions recipes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def post(self, request):
if recipe_form.is_valid():
recipe = recipe_form.save(commit=False)
recipe.author = User.objects.get(id=request.user.id)
recipe.image = request.FILES['image']
recipe.save()
messages.success(
self.request,
Expand Down
2 changes: 1 addition & 1 deletion templates/add_recipe.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1 class="page-title">Add Recipe</h1>
{% load cloudinary %}
<div class="col-11 col-md-8 col-lg-6 mt-3">
<!-- Add Recipe Form -->
<form method="post" class="mb-5 form-font" enctype="multipart/form-data">
<form method="post" class="mb-5 form-font" enctype="multipart/form-data">
{{ form | crispy }}
{% csrf_token %}
<a class="btn btn-signup form-font" href="{% url 'all_recipes' %}">Cancel</a>
Expand Down

0 comments on commit 09f9c79

Please sign in to comment.