Hey guys,

I have the following code in models.py file in one of my apps:

def get_upload_path(instance, filename):
    extension = filename.split('.')[-1]
    return "employees/media/users/{0}/profile_picture.{1}".format(
instance.user.id, extension)

class Employee(models.Model):
    # some attributes here
    profile_picture = models.ImageField(upload_to=get_upload_path,
blank=True, null=True)

I am getting the following error when I try to add an Employee via the
admin interface:

AttributeError at /admin/employees/employee/add/

'Employee' object has no attribute 'user'

*I don't know where this error is stemming from.* I took the
get_upload_path function from the official Django FIleField documentation
<https://docs.djangoproject.com/en/3.1/ref/models/fields/#filefield>.

Any ideas as to what is going on here?

Best,
Mislav

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABTqP_FcyzEXhtyBM--khtnsdHhfszi9vtmt-bY3TUsU0KWmLg%40mail.gmail.com.

Reply via email to