Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add admin model for image assets #454

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openedx/features/sdaia_features/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = "openedx.features.sdaia_features.apps.SdaiaFeaturesConfig"
16 changes: 16 additions & 0 deletions openedx/features/sdaia_features/admin.py
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)
7 changes: 7 additions & 0 deletions openedx/features/sdaia_features/apps.py
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 openedx/features/sdaia_features/migrations/0001_initial.py
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.
15 changes: 15 additions & 0 deletions openedx/features/sdaia_features/models.py
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
Loading