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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f07b-2c46c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f07b-2c46c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?