Skip to content

Commit

Permalink
Add words as tags in shares (Closes #75)
Browse files Browse the repository at this point in the history
  • Loading branch information
giobber committed Sep 16, 2023
1 parent 3cbed60 commit bf1f14d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apps/website/migrations/0013_share_words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.5 on 2023-09-16 17:56

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("website", "0012_landscape_enabled_alter_landscape_domain"),
]

operations = [
migrations.AddField(
model_name="share",
name="words",
field=models.ManyToManyField(
blank=True, related_name="shares", to="website.word"
),
),
]
2 changes: 2 additions & 0 deletions apps/website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Share(LocationModel):
message = models.TextField(max_length=500)
landscape = models.ForeignKey("Landscape", on_delete=models.CASCADE)

words = models.ManyToManyField("Word", related_name="shares", blank=True)

def __str__(self):
message = textwrap.shorten(self.message, width=20, placeholder="...")
return f"{super().__str__()} [{message}]"
Expand Down
2 changes: 2 additions & 0 deletions apps/website/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def on_share_creation_update_frequencies(
word.full_clean()
word.save()

instance.words.add(word)

wf, _ = models.WordFrequency.objects.get_or_create(place=place, word=word)
wf.frequency = F("frequency") + 1
wf.save()
Expand Down

0 comments on commit bf1f14d

Please sign in to comment.