mirror of
https://github.com/barkeser2002/offline-db.git
synced 2026-09-25 06:39:51 +03:00
- Added `Badge` and `UserBadge` models in `users` app. - Implemented `check_badges` service to award badges based on activity (Binge Watcher, Supporter, Veteran). - Added `post_save` signal on `WatchLog` to trigger badge checking automatically. - Added data migration to seed initial badges. - Added tests for badge logic. - Current Focus Mode: C (The Architect) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
# Generated by Django 5.0.6 on 2025-01-27 12:00
|
|
|
|
from django.db import migrations
|
|
|
|
def create_initial_badges(apps, schema_editor):
|
|
Badge = apps.get_model('users', 'Badge')
|
|
badges = [
|
|
{
|
|
'slug': 'binge-watcher',
|
|
'name': 'Binge Watcher',
|
|
'description': 'Watched 5 episodes in 24 hours',
|
|
'icon_url': '/static/badges/binge-watcher.png'
|
|
},
|
|
{
|
|
'slug': 'supporter',
|
|
'name': 'Supporter',
|
|
'description': 'Premium Member',
|
|
'icon_url': '/static/badges/supporter.png'
|
|
},
|
|
{
|
|
'slug': 'veteran',
|
|
'name': 'Veteran',
|
|
'description': 'Member for over 1 year',
|
|
'icon_url': '/static/badges/veteran.png'
|
|
}
|
|
]
|
|
for badge_data in badges:
|
|
if not Badge.objects.filter(slug=badge_data['slug']).exists():
|
|
Badge.objects.create(**badge_data)
|
|
|
|
def remove_initial_badges(apps, schema_editor):
|
|
Badge = apps.get_model('users', 'Badge')
|
|
Badge.objects.filter(slug__in=['binge-watcher', 'supporter', 'veteran']).delete()
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('users', '0002_badge_userbadge'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(create_initial_badges, remove_initial_badges),
|
|
]
|