neutronX / django-markdownx

Comprehensive Markdown plugin built for Django
https://neutronx.github.io/django-markdownx/
Other
839 stars 152 forks source link

Ability to set a media path per MarkdownxField #264

Open ezarowny opened 5 months ago

ezarowny commented 5 months ago

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)