forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add admin model for image assets
- Loading branch information
Showing
6 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = "openedx.features.sdaia_features.apps.SdaiaFeaturesConfig" |
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,16 @@ | ||
from django.contrib import admin | ||
from django.utils.safestring import mark_safe | ||
|
||
from .models import ImageAsset | ||
|
||
|
||
class ImageAssetAdmin(admin.ModelAdmin): | ||
list_display = ("title", "image_display", "description") | ||
|
||
def image_display(self, obj): | ||
return mark_safe(f'<img src="{obj.image.url}" width="50" height="50" />') | ||
|
||
image_display.short_description = "Image" | ||
|
||
|
||
admin.site.register(ImageAsset, ImageAssetAdmin) |
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,7 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
from django.apps import AppConfig | ||
|
||
|
||
class SdaiaFeaturesConfig(AppConfig): | ||
name = "openedx.features.sdaia_features" |
23 changes: 23 additions & 0 deletions
23
openedx/features/sdaia_features/migrations/0001_initial.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,23 @@ | ||
from django.db import migrations, models | ||
from django.conf import settings | ||
import storages.backends.s3 | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ImageAsset', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=255)), | ||
('image', models.ImageField(storage=storages.backends.s3.S3Storage(bucket_name=settings.ASSET_BUCKET), upload_to='image_assets/')), | ||
('description', models.TextField(blank=True, null=True)), | ||
], | ||
), | ||
] |
Empty file.
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,15 @@ | ||
from django.db import models | ||
from django.conf import settings | ||
from storages.backends.s3boto3 import S3Boto3Storage | ||
|
||
|
||
class ImageAsset(models.Model): | ||
title = models.CharField(max_length=255) | ||
image = models.ImageField( | ||
upload_to="image_assets/", | ||
storage=S3Boto3Storage(bucket_name=settings.ASSET_BUCKET), | ||
) | ||
description = models.TextField(blank=True, null=True) | ||
|
||
def __str__(self): | ||
return self.title |