Q:

how to get datetime instance?

Well it is look like simple question. but i am in the learning stage can`t figure out.
This is my model class
class Store(models.Model):
    file = models.FileField(upload_to=content_file_name)
    file_name = models.CharField(max_length=100)
    created_date = models.DateTimeField(auto_now_add=True)
    userfild = models.ForeignKey(user,null=True, blank=True)

Ok for some clarification i just included my content_file_name function here
def content_file_name(instance, filename):
    return os.path.join(
      "user_%d" % instance.created_date, filename)

but the output of the folder structure looks like this 
`None`
----filename

i can get the file_name instance like this --> intance.file_name
but when i enter instance.created_date it is return 'None' value.
What i am missing.? And my another doubt is i set it DateTimeField as auto_now_add=True So it`s saved into the db when form is submitted. But why None return?

A:

auto_now_add is not populated until the object is saved. If you want a default that is applied as soon as the object is instantiated, use the default parameter with a callable:
created_date = models.DateTimeField(default=datetime.datetime.now)

