Skip to content

Commit

Permalink
feat: add admin model for image assets
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza-56 authored and Ali Salman committed Nov 29, 2023
1 parent 0581a93 commit 7f1a04b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
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

0 comments on commit 7f1a04b

Please sign in to comment.