Refactor keyword handling: Replace 'intent' with 'country' across backend and frontend
- Updated AutomationService to include estimated_word_count. - Increased stage_1_batch_size from 20 to 50 in AutomationViewSet. - Changed Keywords model to replace 'intent' property with 'country'. - Adjusted ClusteringService to allow a maximum of 50 keywords for clustering. - Modified admin and management commands to remove 'intent' and use 'country' instead. - Updated serializers to reflect the change from 'intent' to 'country'. - Adjusted views and filters to use 'country' instead of 'intent'. - Updated frontend forms, filters, and pages to replace 'intent' with 'country'. - Added migration to remove 'intent' field and add 'country' field to SeedKeyword model.
This commit is contained in:
@@ -548,18 +548,18 @@ class IndustrySectorAdmin(Igny8ModelAdmin):
|
||||
@admin.register(SeedKeyword)
|
||||
class SeedKeywordAdmin(Igny8ModelAdmin):
|
||||
"""SeedKeyword admin - Global reference data, no account filtering"""
|
||||
list_display = ['keyword', 'industry', 'sector', 'volume', 'difficulty', 'intent', 'is_active', 'created_at']
|
||||
list_filter = ['is_active', 'industry', 'sector', 'intent']
|
||||
list_display = ['keyword', 'industry', 'sector', 'volume', 'difficulty', 'country', 'is_active', 'created_at']
|
||||
list_filter = ['is_active', 'industry', 'sector', 'country']
|
||||
search_fields = ['keyword']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
actions = ['delete_selected'] # Enable bulk delete
|
||||
|
||||
fieldsets = (
|
||||
('Keyword Info', {
|
||||
'fields': ('keyword', 'industry', 'sector', 'is_active')
|
||||
'fields': ('keyword', 'industry', 'sector', 'country', 'is_active')
|
||||
}),
|
||||
('SEO Metrics', {
|
||||
'fields': ('volume', 'difficulty', 'intent')
|
||||
'fields': ('volume', 'difficulty')
|
||||
}),
|
||||
('Timestamps', {
|
||||
'fields': ('created_at', 'updated_at')
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-17 06:04
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('igny8_core_auth', '0017_add_history_tracking'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveIndex(
|
||||
model_name='seedkeyword',
|
||||
name='igny8_seed__intent_15020d_idx',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='seedkeyword',
|
||||
name='intent',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='seedkeyword',
|
||||
name='country',
|
||||
field=models.CharField(choices=[('US', 'United States'), ('CA', 'Canada'), ('GB', 'United Kingdom'), ('AE', 'United Arab Emirates'), ('AU', 'Australia'), ('IN', 'India'), ('PK', 'Pakistan')], default='US', help_text='Target country for this keyword', max_length=2),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='seedkeyword',
|
||||
index=models.Index(fields=['country'], name='igny8_seed__country_4127a5_idx'),
|
||||
),
|
||||
]
|
||||
@@ -517,11 +517,14 @@ class SeedKeyword(models.Model):
|
||||
These are canonical keywords that can be imported into account-specific Keywords.
|
||||
Non-deletable global reference data.
|
||||
"""
|
||||
INTENT_CHOICES = [
|
||||
('informational', 'Informational'),
|
||||
('navigational', 'Navigational'),
|
||||
('commercial', 'Commercial'),
|
||||
('transactional', 'Transactional'),
|
||||
COUNTRY_CHOICES = [
|
||||
('US', 'United States'),
|
||||
('CA', 'Canada'),
|
||||
('GB', 'United Kingdom'),
|
||||
('AE', 'United Arab Emirates'),
|
||||
('AU', 'Australia'),
|
||||
('IN', 'India'),
|
||||
('PK', 'Pakistan'),
|
||||
]
|
||||
|
||||
keyword = models.CharField(max_length=255, db_index=True)
|
||||
@@ -533,7 +536,7 @@ class SeedKeyword(models.Model):
|
||||
validators=[MinValueValidator(0), MaxValueValidator(100)],
|
||||
help_text='Keyword difficulty (0-100)'
|
||||
)
|
||||
intent = models.CharField(max_length=50, choices=INTENT_CHOICES, default='informational')
|
||||
country = models.CharField(max_length=2, choices=COUNTRY_CHOICES, default='US', help_text='Target country for this keyword')
|
||||
is_active = models.BooleanField(default=True, db_index=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
@@ -547,7 +550,7 @@ class SeedKeyword(models.Model):
|
||||
models.Index(fields=['keyword']),
|
||||
models.Index(fields=['industry', 'sector']),
|
||||
models.Index(fields=['industry', 'sector', 'is_active']),
|
||||
models.Index(fields=['intent']),
|
||||
models.Index(fields=['country']),
|
||||
]
|
||||
ordering = ['keyword']
|
||||
|
||||
|
||||
@@ -524,14 +524,14 @@ class SeedKeywordSerializer(serializers.ModelSerializer):
|
||||
industry_slug = serializers.CharField(source='industry.slug', read_only=True)
|
||||
sector_name = serializers.CharField(source='sector.name', read_only=True)
|
||||
sector_slug = serializers.CharField(source='sector.slug', read_only=True)
|
||||
intent_display = serializers.CharField(source='get_intent_display', read_only=True)
|
||||
country_display = serializers.CharField(source='get_country_display', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = SeedKeyword
|
||||
fields = [
|
||||
'id', 'keyword', 'industry', 'industry_name', 'industry_slug',
|
||||
'sector', 'sector_name', 'sector_slug',
|
||||
'volume', 'difficulty', 'intent', 'intent_display',
|
||||
'volume', 'difficulty', 'country', 'country_display',
|
||||
'is_active', 'created_at', 'updated_at'
|
||||
]
|
||||
read_only_fields = ['created_at', 'updated_at']
|
||||
|
||||
@@ -839,7 +839,7 @@ class SeedKeywordViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
search_fields = ['keyword']
|
||||
ordering_fields = ['keyword', 'volume', 'difficulty', 'created_at']
|
||||
ordering = ['keyword']
|
||||
filterset_fields = ['industry', 'sector', 'intent', 'is_active']
|
||||
filterset_fields = ['industry', 'sector', 'country', 'is_active']
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
"""Override retrieve to return unified format"""
|
||||
@@ -877,7 +877,7 @@ class SeedKeywordViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
def import_seed_keywords(self, request):
|
||||
"""
|
||||
Import seed keywords from CSV (Admin/Superuser only).
|
||||
Expected columns: keyword, industry_name, sector_name, volume, difficulty, intent
|
||||
Expected columns: keyword, industry_name, sector_name, volume, difficulty, country
|
||||
"""
|
||||
import csv
|
||||
from django.db import transaction
|
||||
@@ -960,7 +960,7 @@ class SeedKeywordViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
sector=sector,
|
||||
volume=int(row.get('volume', 0) or 0),
|
||||
difficulty=int(row.get('difficulty', 0) or 0),
|
||||
intent=row.get('intent', 'informational') or 'informational',
|
||||
country=row.get('country', 'US') or 'US',
|
||||
is_active=True
|
||||
)
|
||||
imported_count += 1
|
||||
@@ -1487,9 +1487,9 @@ def seedkeyword_csv_template(request):
|
||||
response['Content-Disposition'] = 'attachment; filename="seedkeyword_template.csv"'
|
||||
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(['keyword', 'industry', 'sector', 'volume', 'difficulty', 'intent', 'is_active'])
|
||||
writer.writerow(['python programming', 'Technology', 'Software Development', '10000', '45', 'Informational', 'true'])
|
||||
writer.writerow(['medical software', 'Healthcare', 'Healthcare IT', '5000', '60', 'Commercial', 'true'])
|
||||
writer.writerow(['keyword', 'industry', 'sector', 'volume', 'difficulty', 'country', 'is_active'])
|
||||
writer.writerow(['python programming', 'Technology', 'Software Development', '10000', '45', 'US', 'true'])
|
||||
writer.writerow(['medical software', 'Healthcare', 'Healthcare IT', '5000', '60', 'CA', 'true'])
|
||||
|
||||
return response
|
||||
|
||||
@@ -1534,7 +1534,7 @@ def seedkeyword_csv_import(request):
|
||||
defaults={
|
||||
'volume': int(row.get('volume', 0)),
|
||||
'difficulty': int(row.get('difficulty', 0)),
|
||||
'intent': row.get('intent', 'Informational'),
|
||||
'country': row.get('country', 'US'),
|
||||
'is_active': is_active
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user