django-suit
django-suit copied to clipboard
AttributeError: module 'posts.models' has no attribute 'image_upload_to
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?
Does error goes away if you remove django suit from INSTALLED_APPS? I think this is not related to Django Suit
there is no django suit in INSTALLED_APPS.
Just ran into the same issue, just remove all the migration files and run the migrations again, it should work!