JefferyLR JefferyLR - 2 years ago 126
Python Question

Django (Models): how to get instance from foreign key

i'm new to django and sqlite. Is that possible i can get the value from its foreign key that is related to modeldb? I need to save my pdf file under the same directory as the modeldb class. From the above experiment, im got nothing with modelDB.instance /

enter image description here

Answer Source

move that upload function outside the class.

instance refer as the your class instance. So you can do like this

citatiions = models.FileField(...., upload_to=upload) #pass your function name here

check this answerlink

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download