fixup! Add forms for adding recipes and versions
rename to alternative author
This commit is contained in:
parent
8705473454
commit
99594a7e14
|
|
@ -8,7 +8,7 @@ class VersionForm(ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Version
|
||||
fields = ['label', 'slug', 'body', 'author_name']
|
||||
fields = ['label', 'slug', 'body', 'alternative_author']
|
||||
|
||||
def clean_slug(self):
|
||||
recipe = Recipe.objects.get(id=self.recipe_id)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Version(models.Model):
|
|||
slug = models.SlugField(max_length=20, default='original')
|
||||
body = models.TextField(null=True, blank=True)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
author_name = models.CharField(max_length=30, blank=True)
|
||||
alternative_author = models.CharField(max_length=30, blank=True)
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.PROTECT, null=False, blank=False, related_name='versions')
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
let authorNameValue = "";
|
||||
|
||||
function enableAuthorNameInput() {
|
||||
let authorName = document.querySelector("#id_version-author_name")
|
||||
let authorName = document.querySelector("#id_version-alternative_author")
|
||||
|
||||
if (userIsAuthorCheckbox.checked) {
|
||||
authorName.setAttribute("disabled", "");
|
||||
|
|
|
|||
|
|
@ -53,9 +53,9 @@ def add_version(request, slug_recipe):
|
|||
version = version_form.save(commit=False)
|
||||
if version_form.cleaned_data['use_user_for_author']:
|
||||
version.user = request.user
|
||||
version.author_name = ''
|
||||
elif 'author_name' in version_form.cleaned_data:
|
||||
version.author_name = version_form.cleaned_data['author_name']
|
||||
version.alternative_author = ''
|
||||
elif 'alternative_author' in version_form.cleaned_data:
|
||||
version.alternative_author = version_form.cleaned_data['alternative_author']
|
||||
version.recipe = recipe
|
||||
version.save()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue