2

I have this error after saving an avatar while creating an instance of this model (I didn't rewrite any base django model methods):

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def conference_directory_path(instance, filename):
return BASE_DIR+'/static/dialogues/conferences/conference_{0}/avatar/{1}'.format(instance.id, filename)

class Dialogue(models.Model):
    ...
    avatar = models.ImageField(upload_to=conference_directory_path, blank=True)
    ...

Traceback

What's wrong?

Alexander Shpindler
  • 811
  • 1
  • 11
  • 31

1 Answers1

4

You are trying to store a value in your avatar field that's beyond 100 characters the default max_length for file fields.

I'm not sure why you store the absolute path in your avatar field, you can simply set MEDIA_ROOT in your settings file and your upload_to will store relative paths to MEDIA_ROOT only.

You can either do that or add a higher max_length to your file fields.

HassenPy
  • 2,083
  • 1
  • 16
  • 31