django-suit icon indicating copy to clipboard operation
django-suit copied to clipboard

AttributeError: module 'posts.models' has no attribute 'image_upload_to

Open rahul6612 opened this issue 7 years ago • 3 comments

while running python manage.py makemigrations i am getting error

models.py

  • class Post(models.Model): parent = models.ForeignKey("self", blank=True, null=True) user = models.ForeignKey(settings.AUTH_USER_MODEL) content = models.CharField(max_length=2000, validators=[validate_content]) post_images = models.ImageField(upload_to='posts/') liked = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name='liked') reply = models.BooleanField(verbose_name='Is a reply?', default=False) updatd = models.DateTimeField(auto_now=True) timestamp = models.DateTimeField(auto_now_add=True) objects = PostManager()

here another image_upload_to part is in same models.py but it is in comment

remember this section( image_upload_to) is in comment

  • def image_upload_to(instance, filename): content = instance.post.content slug = slugify(content) basename, file_extension = filename.split(".") new_filename = "%s-%s.%s" %(slug, instance.id, file_extension) return "posts/%s/%s" %(slug, new_filename) class PostImages(models.Model): post = models.ForeignKey(Post) image = models.FileField(upload_to=image_upload_to, blank=True, null=True) def str(self): return self.post.content

error is:

field=models.ImageField(blank=True, null=True, upload_to=posts.models.image_upload_to), AttributeError: module 'posts.models' has no attribute 'image_upload_to' how it possible this part (field=models.ImageField(blank=True, null=True, upload_to=posts.models.image_upload_to) is in comment any idea?

rahul6612 avatar Mar 21 '18 13:03 rahul6612

Does error goes away if you remove django suit from INSTALLED_APPS? I think this is not related to Django Suit

darklow avatar Mar 21 '18 14:03 darklow

there is no django suit in INSTALLED_APPS.

rahul6612 avatar Mar 21 '18 15:03 rahul6612

Just ran into the same issue, just remove all the migration files and run the migrations again, it should work!

Aditya-Rajgor avatar Mar 30 '22 04:03 Aditya-Rajgor