django-markdownx icon indicating copy to clipboard operation
django-markdownx copied to clipboard

Ability to set a media path per MarkdownxField

Open ezarowny opened this issue 1 year ago • 0 comments

It would be helpful to be able to set the media path for any given MarkdownxField. Perhaps the default would be whatever is set for MARKDOWNX_MEDIA_PATH?

I'm thinking it would look something like FileField does today:

from django.db import models
from markdownx.models import MarkdownxField

class ModelClass(models.Model):
    markdownx_field = MarkdownxField(upload_to="some/path/")

or using a callable like

import uuid

from django.db import models
from markdownx.models import MarkdownxField

def _file_path_func(instance, filename):
    extension = filename.split(".")[-1]
    return "media/model-class-images/{}.{}".format(uuid.uuid4(), extension)

class ModelClass(models.Model):
    markdownx_field = MarkdownxField(upload_to=_file_path_func)

ezarowny avatar Feb 06 '24 14:02 ezarowny