mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 14:29:36 +02:00
Fix migrations
This commit is contained in:
parent
0911826501
commit
0fdc119028
14 changed files with 226 additions and 72 deletions
|
@ -1,18 +1,20 @@
|
|||
import os
|
||||
from django.contrib import admin
|
||||
from django.utils.html import mark_safe
|
||||
from .models import Adventure, Checklist, ChecklistItem, Collection, Transportation, Note, AdventureImage
|
||||
from .models import Adventure, Checklist, ChecklistItem, Collection, Transportation, Note, AdventureImage, Visit
|
||||
from worldtravel.models import Country, Region, VisitedRegion
|
||||
|
||||
|
||||
class AdventureAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'type', 'user_id', 'is_public')
|
||||
list_filter = ('type', 'user_id', 'is_public')
|
||||
search_fields = ('name',)
|
||||
|
||||
|
||||
class CountryAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'country_code', 'number_of_regions')
|
||||
list_filter = ('subregion',)
|
||||
search_fields = ('name', 'country_code')
|
||||
|
||||
def number_of_regions(self, obj):
|
||||
return Region.objects.filter(country=obj).count()
|
||||
|
@ -23,6 +25,7 @@ class CountryAdmin(admin.ModelAdmin):
|
|||
class RegionAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'country', 'number_of_visits')
|
||||
list_filter = ('country',)
|
||||
search_fields = ('name', 'country__name')
|
||||
# list_filter = ('country', 'number_of_visits')
|
||||
|
||||
def number_of_visits(self, obj):
|
||||
|
@ -38,6 +41,7 @@ class CustomUserAdmin(UserAdmin):
|
|||
model = CustomUser
|
||||
list_display = ['username', 'email', 'is_staff', 'is_active', 'image_display']
|
||||
readonly_fields = ('uuid',)
|
||||
search_fields = ('username', 'email')
|
||||
fieldsets = UserAdmin.fieldsets + (
|
||||
(None, {'fields': ('profile_pic', 'uuid', 'public_profile')}),
|
||||
)
|
||||
|
@ -52,6 +56,21 @@ class CustomUserAdmin(UserAdmin):
|
|||
class AdventureImageAdmin(admin.ModelAdmin):
|
||||
list_display = ('user_id', 'image_display')
|
||||
|
||||
def image_display(self, obj):
|
||||
if obj.image:
|
||||
public_url = os.environ.get('PUBLIC_URL', 'http://127.0.0.1:8000').rstrip('/')
|
||||
public_url = public_url.replace("'", "")
|
||||
return mark_safe(f'<img src="{public_url}/media/{obj.profile_pic.name}" width="100px" height="100px"')
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
class VisitAdmin(admin.ModelAdmin):
|
||||
list_display = ('adventure', 'start_date', 'end_date', 'notes')
|
||||
list_filter = ('start_date', 'end_date')
|
||||
search_fields = ('notes',)
|
||||
|
||||
|
||||
def image_display(self, obj):
|
||||
if obj.image: # Ensure this field matches your model's image field
|
||||
public_url = os.environ.get('PUBLIC_URL', 'http://127.0.0.1:8000').rstrip('/')
|
||||
|
@ -77,6 +96,7 @@ admin.site.register(CustomUser, CustomUserAdmin)
|
|||
|
||||
admin.site.register(Adventure, AdventureAdmin)
|
||||
admin.site.register(Collection, CollectionAdmin)
|
||||
admin.site.register(Visit, VisitAdmin)
|
||||
admin.site.register(Country, CountryAdmin)
|
||||
admin.site.register(Region, RegionAdmin)
|
||||
admin.site.register(VisitedRegion)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue