Hello everyone,
if I create a new instance of a custom content type from the admin
everything work fine, but from the site the view try to upload the image to
a wrong path, and image is not uploaded. The value saved in the
featured_image field in the DB (/static/media/image_name.jpg) does not
correspond with the value set by me (upload_to) in the model.
This is a summary of the code of the files involved. Is there something I'm
doing wrong?
*in models.py*
class Recipe(Displayable, AdminThumbMixin):
featured_image = FileField(upload_to=upload_to(
"recipes.Recipe.featured_image", "recipes"),
format="Image", max_length=255)
admin_thumb_field = "featured_image"
# other fields, Meta, etc.
*in forms.py*
class CreateRecipeForm(forms.ModelForm):
class Meta:
model = Recipe
fields = ["featured_image",]
widgets = {"featured_image": forms.FileInput()}
*in views.py*
def create_recipe(request, template="recipes/create_recipe.html",
extra_context=None):
if request.method == "POST":
form = CreateRecipeForm(request.POST, request.FILES)
if form.is_valid():
form.save()
else:
form = CreateRecipeForm()
context = {"form": form}
context.update(extra_context or {})
return TemplateResponse(request, [template], context)
*in a template*
{% extends "base.html" %}
{% load i18n mezzanine_tags %}
{% block extra_head %}
{{ block.super }}{{ form.media }}{% endif %}
{% endblock %}
{% block main %}
<form method="post" enctype="multipart/form-data">
{% fields_for form %}
<button type="submit">{% trans "Submit" %}</button>
</form>
{% endblock %}
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.