Re: What is the work of instance & filename which is passing as parameter?

2021-09-11 Thread Hella thor
For Chinese programmers,it's money Tanjina Sharmin 于2021年9月3日周五 下午8:25写道: > def path_and_renamecsv(instance, filename): > upload_to = 'attendancesheet' > ext = filename.split('.')[-1] > # get filename > if instance.pk: > filename = '{}.{}'.format(instance.pk, ext) > else: > # set filename as

Re: What is the work of instance & filename which is passing as parameter?

2021-09-03 Thread Sky Lord
So right here what does the filename changes to? On Fri, Sep 3, 2021, 1:25 PM Tanjina Sharmin wrote: > def path_and_renamecsv(instance, filename): > upload_to = 'attendancesheet' > ext = filename.split('.')[-1] > # get filename > if instance.pk: > filename = '{}.{}'.format(instance.pk, ext) >

Re: What is the work of instance & filename which is passing as parameter?

2021-09-03 Thread Kasper Laudrup
Not sure what you mean by "work of", but Python is a dynamically typed language so you can really pass whatever type you want to the function. This line: > ext = filename.split('.')[-1] looks like the filename parameter is most likely expected to be a string and this line: > if instance.pk:

What is the work of instance & filename which is passing as parameter?

2021-09-03 Thread Tanjina Sharmin
def path_and_renamecsv(instance, filename): upload_to = 'attendancesheet' ext = filename.split('.')[-1] # get filename if instance.pk: filename = '{}.{}'.format(instance.pk, ext) else: # set filename as random string filename = '{}.{}'.format(uuid4().hexq, ext) # return the whole path to the file