Giter Club home page Giter Club logo

Comments (5)

etianen avatar etianen commented on August 30, 2024

You can use AWS_S3_KEY_PREFIX and AWS_S3_KEY_PREFIX_STATIC to do just this!
:)

https://github.com/etianen/django-s3-storage#available-settings

On Tue, 17 Nov 2015 at 13:37 Jón Levy [email protected] wrote:

Would be great if I I could add a directory prefix setting to uploaded
files so I can use the same bucket for different projects.

Example:

my-s3-bucket-name/project1/media
my-s3-bucket-name/project2/media

Here, project1 and project2 would be added to e.g.
django_s3_storage.storage.dir_prefix setting.


Reply to this email directly or view it on GitHub
#7.

from django-s3-storage.

busla avatar busla commented on August 30, 2024

Ohh, thought it was for file prefixing :-)

I suggest the following changes to the docs:

Current:
# A prefix to add to the start of all uploaded files.

Suggestion:
# A prefix to add to the start of all uploaded files, e.g. a directory name to upload files to a subfolder in your bucket

from django-s3-storage.

etianen avatar etianen commented on August 30, 2024

Well, if you end it in a slash, it'll be a directory. If you don't, it'll
be a file prefix.

S3 doesn't really have much concept of directories. It's a key prefix for
S3 keys.

On Tue, 17 Nov 2015 at 13:54 Jón Levy [email protected] wrote:

Ohh, thought it was for file prefixing :-)

I suggest the following changes to the docs:

Current:

A prefix to add to the start of all uploaded files.

Suggestion:

A prefix to add to the start of all uploaded files, e.g. a directory

name to upload files to a subfolder in your bucket


Reply to this email directly or view it on GitHub
#7 (comment)
.

from django-s3-storage.

pljspahn avatar pljspahn commented on August 30, 2024

I know this is old, but how would I use a prefix based on the value of a related field?

I would like all images to be in a folder named with the value of a sku field I have on the related model.

class Mymodel(models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField(max_length=100, default='', blank=True)
    sku = models.CharField(max_length=12)
    description = models.TextField()

    class Meta:
        ordering = ['sku']

    def __str__(self):
        return self.name


class Myimage(models.Model):
    name = models.CharField(max_length=100)

    # How can I append the upload_to value with the sku value of the related model?
    image = models.ImageField(upload_to='images')

    description = models.CharField(max_length=100, default='', blank=True)
    related_model = models.ForeignKey(Mymodel, on_delete=models.CASCADE, related_name='images')

    def __str__(self):
        return self.image.url

from django-s3-storage.

etianen avatar etianen commented on August 30, 2024

from django-s3-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.