Y
Y
y_o_l_k_i_n___e_g_o_r2021-09-25 08:50:09
Django
y_o_l_k_i_n___e_g_o_r, 2021-09-25 08:50:09

How to change upload_to in django model?

there is this model:

class File(models.Model):
    owner = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
    file = models.FileField(upload_to='/files/')
    file_name = models.TextField(blank=False)
    file_full_name = models.TextField(blank=False, unique=True)
    file_extension = models.TextField(blank=False)
    date_of_creation = models.DateTimeField(auto_now_add=True)


It is necessary that the following path be in the upload_to field:
имя_пользователя/files/
How can I ownerget the usernameuser from the field when creating?
Or how to change upload_to when creating a model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kirillinyakin, 2021-09-25
@y_o_l_k_i_n___e_g_o_r

Here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question