Skip to content

Commit

Permalink
fixed models.py for wordlist: word should be unique and mandatory, ex…
Browse files Browse the repository at this point in the history
…planation should also be mandatory
  • Loading branch information
freandste committed Nov 10, 2024
1 parent 26b6081 commit 6530ace
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
8 changes: 4 additions & 4 deletions chemie/wordlist/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.28 on 2024-11-10 10:35
# Generated by Django 2.2.28 on 2024-11-10 11:54

from django.conf import settings
from django.db import migrations, models
Expand Down Expand Up @@ -45,7 +45,7 @@ class Migration(migrations.Migration):
('date', models.DateField(auto_now_add=True, verbose_name='Dato')),
('picture', models.ImageField(blank=True, null=True, upload_to='posters', verbose_name='Bilde')),
('secret', models.BooleanField(default=False, verbose_name='Hemmelig?')),
('word', models.CharField(blank=True, max_length=100, verbose_name='infinitiv')),
('word', models.CharField(max_length=100, unique=True, verbose_name='infinitiv')),
('present', models.CharField(blank=True, max_length=100, verbose_name='presens')),
('past', models.CharField(blank=True, max_length=100, verbose_name='preteritum')),
('future', models.CharField(blank=True, max_length=100, verbose_name='presens futurum')),
Expand All @@ -64,7 +64,7 @@ class Migration(migrations.Migration):
('date', models.DateField(auto_now_add=True, verbose_name='Dato')),
('picture', models.ImageField(blank=True, null=True, upload_to='posters', verbose_name='Bilde')),
('secret', models.BooleanField(default=False, verbose_name='Hemmelig?')),
('word', models.CharField(blank=True, max_length=100, verbose_name='ubestemt_entall')),
('word', models.CharField(max_length=100, unique=True, verbose_name='ubestemt_entall')),
('indefinite_plural', models.CharField(blank=True, max_length=100, verbose_name='ubestemt_flertall')),
('definite_singular', models.CharField(blank=True, max_length=100, verbose_name='bestemt_entall')),
('definite_plural', models.CharField(blank=True, max_length=100, verbose_name='bestemt_flertall')),
Expand All @@ -83,7 +83,7 @@ class Migration(migrations.Migration):
('date', models.DateField(auto_now_add=True, verbose_name='Dato')),
('picture', models.ImageField(blank=True, null=True, upload_to='posters', verbose_name='Bilde')),
('secret', models.BooleanField(default=False, verbose_name='Hemmelig?')),
('word', models.CharField(blank=True, max_length=100, verbose_name='positiv')),
('word', models.CharField(max_length=100, unique=True, verbose_name='positiv')),
('comparative', models.CharField(blank=True, max_length=100, verbose_name='komparativ')),
('superlative', models.CharField(blank=True, max_length=100, verbose_name='superlativ')),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Forfatter')),
Expand Down
8 changes: 4 additions & 4 deletions chemie/wordlist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Noun(AbstractWord):
word = models.CharField(
max_length=100,
verbose_name="ubestemt_entall",
unique=False,
blank=True,
unique=True,
blank=False,
)
indefinite_plural = models.CharField(
max_length=100,
Expand All @@ -62,7 +62,7 @@ def __str__(self):

class Verb(AbstractWord):
word = models.CharField(
max_length=100, verbose_name="infinitiv", unique=False, blank=True
max_length=100, verbose_name="infinitiv", unique=True, blank=False
)
present = models.CharField(
max_length=100, verbose_name="presens", unique=False, blank=True
Expand All @@ -83,7 +83,7 @@ def __str__(self):

class Adjective(AbstractWord):
word = models.CharField(
max_length=100, verbose_name="positiv", unique=False, blank=True
max_length=100, verbose_name="positiv", unique=True, blank=False
)
comparative = models.CharField(
max_length=100, verbose_name="komparativ", unique=False, blank=True
Expand Down
35 changes: 17 additions & 18 deletions chemie/wordlist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ def ordListe(request):
def createWord(request):
form = CheckWhatFormForm()
formindex = 0



if request.method == "POST" and "check" in request.POST:
if request.method == "POST" and "check" in request.POST:
if request.POST["choice"] == "1" and "check" in request.POST:
form = WordInput()
formindex = 1
Expand All @@ -208,9 +206,7 @@ def createWord(request):
form = AdjectiveInput()
formindex = 4


if request.method == "POST" and "check" not in request.POST:

if ("nytt_tag_1" or "tag_1") in request.POST:
form = WordInput(data=request.POST, files=request.FILES)
if ("nytt_tag_2" or "tag_2") in request.POST:
Expand All @@ -220,9 +216,7 @@ def createWord(request):
if ("nytt_tag_4" or "tag_4") in request.POST:
form = AdjectiveInput(data=request.POST, files=request.FILES)


if "nytt_tag_3" in request.POST and form.is_valid():

form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -235,7 +229,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:innsending"))

if "nytt_tag_2" in request.POST and form.is_valid():
elif "nytt_tag_2" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -248,7 +242,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:innsending"))

if "nytt_tag_4" in request.POST and form.is_valid():
elif "nytt_tag_4" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -261,7 +255,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:innsending"))

if "nytt_tag_1" in request.POST and form.is_valid():
elif "nytt_tag_1" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -274,7 +268,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:innsending"))

if "tag_3" in request.POST and form.is_valid():
elif "tag_3" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -287,7 +281,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:index"))

if "tag_2" in request.POST and form.is_valid():
elif "tag_2" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -300,7 +294,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:index"))

if "tag_4" in request.POST and form.is_valid():
elif "tag_4" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -313,7 +307,7 @@ def createWord(request):
)
return HttpResponseRedirect(reverse("wordlist:index"))

if "tag_1" in request.POST and form.is_valid():
elif "tag_1" in request.POST and form.is_valid():
form_instace = form.save(commit=False)
form_instace.author = request.user
form_instace.save()
Expand All @@ -325,8 +319,15 @@ def createWord(request):
extra_tags="Big slay; et nytt ord!",
)
return HttpResponseRedirect(reverse("wordlist:index"))
else:
messages.add_message(
request,
messages.ERROR,
f"Ditt ord ble ikke lagret.",
extra_tags="Dette kan skyldes ",
)

context = {"form": form, "formindex":formindex}
context = {"form": form, "formindex": formindex}
return render(request, "createWord.html", context)


Expand Down Expand Up @@ -419,9 +420,7 @@ def details(
if klassetall == 4:
ordet = (get_object_or_404(Word, id=pk), klassetall)

context = {
"ord": ordet
}
context = {"ord": ordet}
return render(request, "details.html", context)


Expand Down

0 comments on commit 6530ace

Please sign in to comment.