Reference to upload file path of django model

I have two attributes, file,url. I want to refer to the file path uploaded by file when the url submission is empty. What should I do? Thank you.

class xxx(models.Model):
    file = models.FileField(upload_to=files_path, blank=True, null=True, verbose_name="")
    url = models.URLField(default=base_url + , blank=True, null=True, verbose_name="")
Mar.25,2021

No, because the ORM mapping has been created when the user submits it, and you can't assign it dynamically. You can only construct it yourself when the user submits it.


`def __init__(self, file_path):` -sharp ?
,.,.

you can consider trying the post_save signal and copying the file path if url is empty.

Menu