Browse Source

feat(bookmark): add article service choice to bookmark model

- Introduced a new service choice 'Article' to the Bookmark model.
- Updated the database migration to reflect the new service choice in the 'service' field of the Bookmark model.
- Enhanced the service validation logic to include checks for the new 'Article' service type.
master
mortezaei 6 months ago
parent
commit
645c03a08c
  1. 18
      apps/bookmark/migrations/0003_add_article_service_choice.py
  2. 4
      apps/bookmark/models/bookmark.py

18
apps/bookmark/migrations/0003_add_article_service_choice.py

@ -0,0 +1,18 @@
# Generated by Django 5.1.8 on 2025-11-21 03:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookmark', '0002_rate'),
]
operations = [
migrations.AlterField(
model_name='bookmark',
name='service',
field=models.CharField(choices=[('library', 'Library'), ('podcast', 'Podcast'), ('hadith', 'Hadith'), ('video', 'Video'), ('article', 'Article')], max_length=20, verbose_name='Service'),
),
]

4
apps/bookmark/models/bookmark.py

@ -15,6 +15,7 @@ class Bookmark(models.Model):
PODCAST = 'podcast', 'Podcast' PODCAST = 'podcast', 'Podcast'
HADITH = 'hadith', 'Hadith' HADITH = 'hadith', 'Hadith'
VIDEO = 'video', 'Video' VIDEO = 'video', 'Video'
ARTICLE = 'article', 'Article'
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='bookmarks', verbose_name='User') user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='bookmarks', verbose_name='User')
service = models.CharField(max_length=20, choices=ServiceChoices.choices, verbose_name='Service') service = models.CharField(max_length=20, choices=ServiceChoices.choices, verbose_name='Service')
@ -75,4 +76,7 @@ class Bookmark(models.Model):
elif service == cls.ServiceChoices.VIDEO: elif service == cls.ServiceChoices.VIDEO:
from apps.video.models import Video from apps.video.models import Video
return Video.objects.filter(id=content_id).exists() return Video.objects.filter(id=content_id).exists()
elif service == cls.ServiceChoices.ARTICLE:
from apps.article.models import Article
return Article.objects.filter(id=content_id).exists()
return False return False
Loading…
Cancel
Save