Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rahul6612 opened this issue Mar 21, 2018 · 3 comments
Open

Comments

@rahul6612
Copy link

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?

@darklow
Copy link
Owner

darklow commented Mar 21, 2018

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

@rahul6612
Copy link
Author

there is no django suit in INSTALLED_APPS.

@Aditya-Rajgor
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants