Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8532031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:37:14+00:00 2026-06-11T09:37:14+00:00

I am going through the following tutorial , and the models.py code seems to

  • 0

I am going through the following tutorial, and the models.py code seems to be broken (I’m on a Mac and Django 1.4.1).

Here’s the models.py code:

from django.db import models

from django.contrib.auth.models import User
from django.contrib import admin

class Album(models.Model):
    title = models.CharField(max_length=60)
    public = models.BooleanField(default=False)
    def __unicode__(self):
        return self.title

class Tag(models.Model):
    tag = models.CharField(max_length=50)
    def __unicode__(self):
        return self.tag

class Image(models.Model):
    title = models.CharField(max_length=60, blank=True, null=True)
    image = models.FileField(upload_to='images/')
    tags = models.ManyToManyField(Tag, blank=True)
    albums = models.ManyToManyField(Tag, blank = True)
    created = models.DateTimeField(auto_now_add=True)
    rating = models.IntegerField(default=50)
    width = models.IntegerField(blank=True, null=True)
    height = models.IntegerField(blank=True, null=True)
    user = models.ForeignKey(User, null=True, blank=True)
    def __unicode__(self):
        return self.image.name

    def save(self, *args, **kwargs):
        """Save image dimensions."""
        super(Image, self).save(*args, **kwargs)
        im = PImage.open(os.path.join(MEDIA_ROOT, self.image.name))
        self.width, self.height = im.size
        super(Image, self).save(*args, ** kwargs)

    def size(self):
        """Image size."""
        return "%s x %s" % (self.width, self.height)

    def __unicode__(self):
        return self.image.name

    def tags_(self):
        lst = [x[1] for x in self.tags.values_list()]
        return str(join(lst, ', '))

    def albums_(self):
        lst = [x[1] for x in self.albums.values_list()]
        return str(join(lst, ', '))

    def thumbnail(self):
        return """<a href="/media/%s"><img border="0" alt="" src="/media/%s" height="40" /></a>""" % (
                                                                    (self.image.name, self.image.name))
    thumbnail.allow_tags = True

class AlbumAdmin(admin.ModelAdmin):
    search_fields = ['title']
    list_display = ['title']

class TagAdmin(admin.ModelAdmin):
    list_display = ['tag']

class ImageAdmin(admin.ModelAdmin):
    search_fields = ['title']
    list_display = ["__unicode__", "title", "user", "rating", "size", "tags_", "albums_",
        "thumbnail", "created"]
    list_filter = ["tags", "albums", "user"]

    def save_model(self, request, obj, form, change):
        obj.user = request.user
        obj.save()

admin.site.register(Album, AlbumAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Image, ImageAdmin)

Here’s the error I’m getting when I try to sync the database:

Error: One or more models did not validate:
photoapp.image: Accessor for m2m field 'tags' clashes with related m2m field 'Tag.image_set'. Add a related_name argument to the definition for 'tags'.
photoapp.image: Accessor for m2m field 'albums' clashes with related m2m field 'Tag.image_set'. Add a related_name argument to the definition for 'albums'.

Any help much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:37:15+00:00Added an answer on June 11, 2026 at 9:37 am

    You have duplicate M2M with Tag as albums you my want to change that for Album. Also good idea to have related name as well

    tags = models.ManyToManyField(Tag, blank=True)
    albums = models.ManyToManyField(Tag, blank = True,)
    

    change to

    tags = models.ManyToManyField(Tag, blank=True, related_name="img_tags")
    albums = models.ManyToManyField(Album, blank = True, related_name="img_albums")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following a video tutorial from O'reilly media going through the basics
I am going through a tutorial that mentions the following method: -(void)layoutSubviews located in
While going through Effective C++ (by Scott Meyers), I came across the following code
I am going through the following tutorial . I need to get thumbnail images
While going through a Zend tutorial , I came across the following statement: Note
I am currently working through the tutorial on Django's website. Upon completing the following
I'm going through the second edition of Ruby on Rails Tutorial (http://ruby.railstutorial.org/). I'm following
I'm going through the GAE webapp2 tutorial (runtime 2.7) using GoogleAppEngineLauncher on my Mac,
I get the following error when going through the WCF tutorial. HTTP could not
While Going through the java tutorial on sun site, I see following piece of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.