from django.contrib import admin

from api import models


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'country', )


class EventAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'status', 'location', 'country', 'start_date')
    list_editable = ('status',)
    list_filter = ('status', 'start_date')
    filter_horizontal = ('audience',)
    filter_horizontal = ('theme',)

admin.site.register(models.UserProfile, UserProfileAdmin)
admin.site.register(models.Event, EventAdmin)
admin.site.register(models.events.EventAudience)
admin.site.register(models.events.EventTheme)

from django.contrib import admin

from api import models


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'country', )
    search_fields = ['user__email', 'user__username', 'user__first_name', 'user__last_name']

class EventAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'status', 'location', 'country', 'start_date')
    list_editable = ('status',)
    list_filter = ('status', 'start_date')
    filter_horizontal = ('audience',)
    filter_horizontal = ('theme',)

admin.site.register(models.UserProfile, UserProfileAdmin)
admin.site.register(models.Event, EventAdmin)
admin.site.register(models.events.EventAudience)
admin.site.register(models.events.EventTheme)

Allow searching by email, username and names in user profiles
Allow searching by email, username and names in user profiles

This is needed as user profiles need to be edited for setting main
contact flag and ambassador roles.

  from django.contrib import admin
  
  from api import models
  
  
  class UserProfileAdmin(admin.ModelAdmin):
      list_display = ('user', 'country', )
- 
+     search_fields = ['user__email', 'user__username', 'user__first_name', 'user__last_name']
  
  class EventAdmin(admin.ModelAdmin):
      prepopulated_fields = {'slug': ('title',)}
      list_display = ('title', 'status', 'location', 'country', 'start_date')
      list_editable = ('status',)
      list_filter = ('status', 'start_date')
      filter_horizontal = ('audience',)
      filter_horizontal = ('theme',)
  
  admin.site.register(models.UserProfile, UserProfileAdmin)
  admin.site.register(models.Event, EventAdmin)
  admin.site.register(models.events.EventAudience)
  admin.site.register(models.events.EventTheme)
  
Allow searching by email, username and names in user profiles
## Code Before:
from django.contrib import admin

from api import models


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'country', )


class EventAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'status', 'location', 'country', 'start_date')
    list_editable = ('status',)
    list_filter = ('status', 'start_date')
    filter_horizontal = ('audience',)
    filter_horizontal = ('theme',)

admin.site.register(models.UserProfile, UserProfileAdmin)
admin.site.register(models.Event, EventAdmin)
admin.site.register(models.events.EventAudience)
admin.site.register(models.events.EventTheme)

## Instruction:
Allow searching by email, username and names in user profiles
## Code After:
from django.contrib import admin

from api import models


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'country', )
    search_fields = ['user__email', 'user__username', 'user__first_name', 'user__last_name']

class EventAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'status', 'location', 'country', 'start_date')
    list_editable = ('status',)
    list_filter = ('status', 'start_date')
    filter_horizontal = ('audience',)
    filter_horizontal = ('theme',)

admin.site.register(models.UserProfile, UserProfileAdmin)
admin.site.register(models.Event, EventAdmin)
admin.site.register(models.events.EventAudience)
admin.site.register(models.events.EventTheme)
