This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refinement of Assets and conversion of Image.
Writing the migrations when converting over an old plugin to use asset is unfortunately a manual task. But it's not as difficult as it sounds.
- Loading branch information
Showing
11 changed files
with
157 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
from django.contrib import admin | ||
|
||
from icekit.utils.admin.mixins import ThumbnailAdminMixin | ||
from polymorphic.admin import PolymorphicChildModelAdmin | ||
|
||
from . import models | ||
|
||
|
||
class ImageAdmin(ThumbnailAdminMixin, admin.ModelAdmin): | ||
list_display = ['thumbnail', 'title', 'alt_text',] | ||
list_display_links = ['alt_text', 'thumbnail'] | ||
filter_horizontal = ['categories', ] | ||
list_filter = ['categories',] | ||
search_fields = ['title', 'alt_text', 'caption', 'admin_notes', 'image'] | ||
|
||
class ImageAdmin(PolymorphicChildModelAdmin): | ||
base_model = models.Image | ||
change_form_template = 'image/admin/change_form.html' | ||
|
||
# ThumbnailAdminMixin attributes | ||
thumbnail_field = 'image' | ||
thumbnail_options = { | ||
'size': (150, 150), | ||
} | ||
|
||
admin.site.register(models.Image, ImageAdmin) |
72 changes: 72 additions & 0 deletions
72
icekit/plugins/image/migrations/0009_assets_20161013_1124.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def create_assets(apps, schema_editor): | ||
# We need to create a new asset for each image | ||
Image = apps.get_model('icekit_plugins_image', 'Image') | ||
Asset = apps.get_model('icekit', 'Asset') | ||
for image in Image.objects.all(): | ||
# Create a new asset | ||
asset = Asset() | ||
asset.admin_notes = image.admin_notes | ||
asset.caption = image.caption | ||
asset.title = image.title | ||
asset.save() | ||
asset.categories.add(*image.categories.all()) | ||
|
||
# Set the asset_ptr on the image | ||
image.asset_ptr = asset | ||
image.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('icekit', '0007_asset'), | ||
('icekit_plugins_image', '0008_auto_20160920_2114'), | ||
('icekit', '0006_auto_20150911_0744'), | ||
] | ||
|
||
operations = [ | ||
# Add the ForeignKey first as not the primary key so we can fake it | ||
migrations.AddField( | ||
model_name='image', | ||
name='asset_ptr', | ||
field=models.OneToOneField(parent_link=True, auto_created=True, default=1, serialize=False, to='icekit.Asset'), | ||
preserve_default=False, | ||
), | ||
# Create asset links for existing images | ||
migrations.RunPython( | ||
create_assets | ||
), | ||
migrations.RemoveField( | ||
model_name='image', | ||
name='admin_notes', | ||
), | ||
migrations.RemoveField( | ||
model_name='image', | ||
name='caption', | ||
), | ||
migrations.RemoveField( | ||
model_name='image', | ||
name='categories', | ||
), | ||
migrations.RemoveField( | ||
model_name='image', | ||
name='id', | ||
), | ||
migrations.RemoveField( | ||
model_name='image', | ||
name='title', | ||
), | ||
# Make asset_ptr the primary key | ||
migrations.AlterField( | ||
model_name='image', | ||
name='asset_ptr', | ||
field=models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='icekit.Asset'), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters