Compare commits
2 commits
4ada3dbc5d
...
6d03a8db2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d03a8db2f | ||
|
|
1512cae857 |
|
|
@ -38,7 +38,7 @@ class VersionForm(ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Version
|
model = Version
|
||||||
fields = ['label', 'slug', 'body', 'author']
|
fields = ['label', 'slug', 'body', 'author', 'img']
|
||||||
|
|
||||||
def clean_slug(self):
|
def clean_slug(self):
|
||||||
slug = self.cleaned_data['slug']
|
slug = self.cleaned_data['slug']
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class Version(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.PROTECT, null=False, blank=False)
|
user = models.ForeignKey(User, on_delete=models.PROTECT, null=False, blank=False)
|
||||||
author = models.CharField(max_length=30, blank=True)
|
author = models.CharField(max_length=30, blank=True)
|
||||||
recipe = models.ForeignKey(Recipe, on_delete=models.PROTECT, null=False, blank=False, related_name='versions')
|
recipe = models.ForeignKey(Recipe, on_delete=models.PROTECT, null=False, blank=False, related_name='versions')
|
||||||
|
img = models.ImageField(null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.recipe.title + ' - ' + self.label
|
return self.recipe.title + ' - ' + self.label
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
{% block title %}{{ title }}{% endblock %}
|
{% block title %}{{ title }}{% endblock %}
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<form action="" method="post" id="version-form">
|
<form action="" method="post" id="version-form" enctype="multipart/form-data">
|
||||||
{%csrf_token %}
|
{%csrf_token %}
|
||||||
{% if recipe_form %}
|
{% if recipe_form %}
|
||||||
{{ recipe_form.as_div }}
|
{{ recipe_form.as_div }}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ def add_version(request, slug):
|
||||||
version_initial = {}
|
version_initial = {}
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
version_form = VersionForm(request.POST, prefix=VERSION_FORM_PREFIX, initial=version_initial, author_placeholder=get_name_of_user(request.user))
|
version_form = VersionForm(request.POST, request.FILES, prefix=VERSION_FORM_PREFIX, initial=version_initial, author_placeholder=get_name_of_user(request.user))
|
||||||
ingredients_formset = IngredientFormSet(request.POST, queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX)
|
ingredients_formset = IngredientFormSet(request.POST, queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX)
|
||||||
version_form.recipe_id = recipe.id # type: ignore
|
version_form.recipe_id = recipe.id # type: ignore
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ def edit_version(request, slug_recipe, slug_version):
|
||||||
return redirect(f"/accounts/login/?next={request.path}")
|
return redirect(f"/accounts/login/?next={request.path}")
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
version_form = VersionForm(request.POST, prefix=VERSION_FORM_PREFIX, instance=version, author_placeholder=get_name_of_user(request.user))
|
version_form = VersionForm(request.POST, request.FILES, prefix=VERSION_FORM_PREFIX, instance=version, author_placeholder=get_name_of_user(request.user))
|
||||||
ingredients_formset = IngredientFormSet(request.POST, queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore
|
ingredients_formset = IngredientFormSet(request.POST, queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore
|
||||||
version_form.recipe_id = recipe.id # type: ignore
|
version_form.recipe_id = recipe.id # type: ignore
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
asgiref==3.5.2
|
asgiref==3.5.2
|
||||||
Django==4.1.4
|
Django==4.1.4
|
||||||
|
Pillow==9.4.0
|
||||||
sqlparse==0.4.3
|
sqlparse==0.4.3
|
||||||
tzdata==2022.7
|
tzdata==2022.7
|
||||||
|
|
|
||||||
|
|
@ -143,3 +143,6 @@ STATIC_URL = 'static/'
|
||||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
||||||
|
MEDIA_URL = 'media/'
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
from django.conf import settings
|
||||||
|
from django.conf.urls.static import static
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
@ -44,3 +46,5 @@ urlpatterns = [
|
||||||
path('accounts/profile/', views.profile, name='profile'),
|
path('accounts/profile/', views.profile, name='profile'),
|
||||||
path('accounts/', include('django.contrib.auth.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue