feat(ad_control): new AdSurface + AdPlacement module for placement-based featured/top events
- New ad_control Django app: AdSurface + AdPlacement models with GLOBAL/LOCAL scope - Admin CRUD API at /api/v1/ad-control/ (JWT-protected): surfaces, placements, picker events - Placement lifecycle: DRAFT → ACTIVE|SCHEDULED → EXPIRED|DISABLED - LOCAL scope: Haversine ≤ 50km from event lat/lng (fixed radius, no config needed) - Consumer APIs: /api/events/featured-events/ and /api/events/top-events/ rewritten to use placement-based queries (same URL paths + response shape — no breaking changes) - Seed command: seed_surfaces --migrate converts existing is_featured/is_top_event booleans - mount: admin_api/urls.py → ad-control/, mobile_api/urls.py → replaced consumer views - settings.py: added ad_control to INSTALLED_APPS
This commit is contained in:
104
ad_control/migrations/0001_initial.py
Normal file
104
ad_control/migrations/0001_initial.py
Normal file
@@ -0,0 +1,104 @@
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('events', '0007_add_is_featured_is_top_event'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AdSurface',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('key', models.CharField(db_index=True, max_length=50, unique=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('description', models.TextField(blank=True, default='')),
|
||||
('max_slots', models.IntegerField(default=8)),
|
||||
('layout_type', models.CharField(
|
||||
choices=[('carousel', 'Carousel'), ('grid', 'Grid'), ('list', 'List')],
|
||||
default='carousel', max_length=20,
|
||||
)),
|
||||
('sort_behavior', models.CharField(
|
||||
choices=[('rank', 'By Rank'), ('date', 'By Date'), ('popularity', 'By Popularity')],
|
||||
default='rank', max_length=20,
|
||||
)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Ad Surface',
|
||||
'verbose_name_plural': 'Ad Surfaces',
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AdPlacement',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('status', models.CharField(
|
||||
choices=[
|
||||
('DRAFT', 'Draft'), ('ACTIVE', 'Active'), ('SCHEDULED', 'Scheduled'),
|
||||
('EXPIRED', 'Expired'), ('DISABLED', 'Disabled'),
|
||||
],
|
||||
db_index=True, default='DRAFT', max_length=20,
|
||||
)),
|
||||
('priority', models.CharField(
|
||||
choices=[('SPONSORED', 'Sponsored'), ('MANUAL', 'Manual'), ('ALGO', 'Algorithm')],
|
||||
default='MANUAL', max_length=20,
|
||||
)),
|
||||
('scope', models.CharField(
|
||||
choices=[
|
||||
('GLOBAL', 'Global \u2014 shown to all users'),
|
||||
('LOCAL', 'Local \u2014 shown to nearby users (50 km radius)'),
|
||||
],
|
||||
db_index=True, default='GLOBAL', max_length=10,
|
||||
)),
|
||||
('rank', models.IntegerField(default=0, help_text='Lower rank = higher position')),
|
||||
('start_at', models.DateTimeField(blank=True, help_text='When this placement becomes active', null=True)),
|
||||
('end_at', models.DateTimeField(blank=True, help_text='When this placement expires', null=True)),
|
||||
('boost_label', models.CharField(
|
||||
blank=True, default='', help_text='Display label e.g. "Featured", "Top Pick", "Sponsored"',
|
||||
max_length=50,
|
||||
)),
|
||||
('notes', models.TextField(blank=True, default='')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('created_by', models.ForeignKey(
|
||||
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name='created_placements', to=settings.AUTH_USER_MODEL,
|
||||
)),
|
||||
('event', models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, related_name='ad_placements',
|
||||
to='events.event',
|
||||
)),
|
||||
('surface', models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, related_name='placements',
|
||||
to='ad_control.adsurface',
|
||||
)),
|
||||
('updated_by', models.ForeignKey(
|
||||
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name='updated_placements', to=settings.AUTH_USER_MODEL,
|
||||
)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Ad Placement',
|
||||
'verbose_name_plural': 'Ad Placements',
|
||||
'ordering': ['rank', '-created_at'],
|
||||
},
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='adplacement',
|
||||
constraint=models.UniqueConstraint(
|
||||
condition=models.Q(('status__in', ['DRAFT', 'ACTIVE', 'SCHEDULED'])),
|
||||
fields=('surface', 'event'),
|
||||
name='unique_active_placement_per_surface',
|
||||
),
|
||||
),
|
||||
]
|
||||
0
ad_control/migrations/__init__.py
Normal file
0
ad_control/migrations/__init__.py
Normal file
Reference in New Issue
Block a user