basic local recipes
This commit is contained in:
parent
b98f87499a
commit
b54da49858
@ -15,7 +15,7 @@ class EmojiWidget(forms.TextInput):
|
||||
js = ('custom/js/form_emoji.js',)
|
||||
|
||||
|
||||
class EditRecipeForm(forms.ModelForm):
|
||||
class ExternalRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'keywords', 'file_path', 'storage', 'file_uid')
|
||||
@ -29,6 +29,19 @@ class EditRecipeForm(forms.ModelForm):
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
||||
|
||||
class InternalRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'instructions', 'keywords')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'keywords': _('Keywords'),
|
||||
'instructions': _('Instructions'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
||||
|
||||
class KeywordForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Keyword
|
||||
|
46
cookbook/migrations/0002_auto_20191113_2224.py
Normal file
46
cookbook/migrations/0002_auto_20191113_2224.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Generated by Django 2.2.7 on 2019-11-13 21:24
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Ingredients',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=128)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='RecipeIngredients',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('unit', models.CharField(max_length=128)),
|
||||
('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cookbook.Ingredients')),
|
||||
],
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='recipe',
|
||||
name='category',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='instructions',
|
||||
field=models.TextField(blank=True),
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Category',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='recipeingredients',
|
||||
name='recipe',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cookbook.Recipe'),
|
||||
),
|
||||
]
|
19
cookbook/migrations/0003_auto_20191113_2235.py
Normal file
19
cookbook/migrations/0003_auto_20191113_2235.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.7 on 2019-11-13 21:35
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0002_auto_20191113_2224'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='storage',
|
||||
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.PROTECT, to='cookbook.Storage'),
|
||||
),
|
||||
]
|
19
cookbook/migrations/0004_auto_20191113_2238.py
Normal file
19
cookbook/migrations/0004_auto_20191113_2238.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.7 on 2019-11-13 21:38
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0003_auto_20191113_2235'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='storage',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cookbook.Storage'),
|
||||
),
|
||||
]
|
@ -46,9 +46,14 @@ class Keyword(models.Model):
|
||||
return "{0} {1}".format(self.icon, self.name)
|
||||
|
||||
|
||||
class Ingredients(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
|
||||
|
||||
class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||
instructions = models.TextField(blank=True)
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
|
||||
file_uid = models.CharField(max_length=256, default="")
|
||||
file_path = models.CharField(max_length=512, default="")
|
||||
link = models.CharField(max_length=512, default="")
|
||||
@ -65,6 +70,12 @@ class Recipe(models.Model):
|
||||
return ', '.join([(x.icon + x.name) for x in self.keywords.all()])
|
||||
|
||||
|
||||
class RecipeIngredients(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
unit = models.CharField(max_length=128)
|
||||
ingredient = models.ForeignKey(Ingredients, models.PROTECT)
|
||||
|
||||
|
||||
class RecipeImport(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||
|
@ -5,7 +5,7 @@ from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import UpdateView, DeleteView
|
||||
|
||||
from cookbook.forms import EditRecipeForm, KeywordForm, StorageForm, SyncForm
|
||||
from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm
|
||||
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ class ImportUpdate(LoginRequiredMixin, UpdateView):
|
||||
|
||||
class RecipeUpdate(LoginRequiredMixin, UpdateView):
|
||||
model = Recipe
|
||||
form_class = EditRecipeForm
|
||||
form_class = ExternalRecipeForm
|
||||
template_name = "generic/edit_template.html"
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -6,14 +6,14 @@ from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import CreateView
|
||||
|
||||
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm
|
||||
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm
|
||||
from cookbook.models import Keyword, Recipe
|
||||
|
||||
|
||||
class RecipeCreate(LoginRequiredMixin, CreateView): # this exists for completeness but is not in use at the moment
|
||||
class RecipeCreate(LoginRequiredMixin, CreateView):
|
||||
template_name = "generic/new_template.html"
|
||||
model = Recipe
|
||||
fields = ['name', 'keywords']
|
||||
form_class = InternalRecipeForm
|
||||
success_url = reverse_lazy('index')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
|
||||
import os
|
||||
from django.contrib import messages
|
||||
from dotenv import load_dotenv
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
@ -125,6 +126,11 @@ USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
LANGUAGES = [
|
||||
('de', _('German')),
|
||||
('en', _('English')),
|
||||
]
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/2.0/howto/static-files/
|
||||
|
||||
|
@ -18,8 +18,7 @@ from django.urls import include, path
|
||||
from django.contrib import admin
|
||||
|
||||
urlpatterns = [
|
||||
path('', lambda r: HttpResponseRedirect('cookbook/')),
|
||||
path('', include('cookbook.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('cookbook/', include('cookbook.urls')),
|
||||
path('accounts/', include('django.contrib.auth.urls')),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user