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 7605219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:06:38+00:00 2026-05-31T00:06:38+00:00

So I am having a problem with adding a ManyToMany Object to my Absolute

  • 0

So I am having a problem with adding a ManyToMany Object to my Absolute URL. Below are my models. Check out the Category class. I know I need to get Category title into the URL.

# Category class
class Category(models.Model):
     title = models.CharField(max_length=128)
     description = models.TextField()

     def __unicode__(self):
     return self.title


# Product class
class Product(models.Model):
    title = models.CharField(max_length=128)
    pub_date = models.DateField('date published')
    slug_title = models.SlugField(editable=False)
    cover_image = models.ImageField(upload_to="images/product/")
    image = models.ManyToManyField(Image)
    category = models.ManyToManyField(Category)
    description = models.TextField()

    def save (self):            
    self.slug_title = slugify(self.title)
    super(Product, self).save()

    def __unicode__(self):
    return self.title

def get_absolute_url(self):
    return ('product_view_url', (), {
        'category': self.category,
        'year': self.pub_date.strftime("%Y"),
        'month': self.pub_date.strftime("%m"),
        'day': self.pub_date.strftime("%d"),
        'id': self.id,
        'slug_title': self.slug_title })

get_absolute_url = models.permalink(get_absolute_url)

Here’s the url.py for product_view_url:

    url(r'^product/(?P<category>.+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<id>.+)/(?P<slug_title>.+)/$', index_views.product_detail, name='product_view_url'),

Below is the view:

    # Product Detail View
   def product_detail(request, id, category, slug_title, year, month, day, template='index/product_detail.html'):

   product = get_object_or_404(Product, id=id, slug_title=slug_title)

   payload = {'product': product}

   return render_to_response(template, payload, context_instance=RequestContext(request))

With this configuration I get a weird URL: ‘http://localhost:8000/product/%3Cdjango.db.models.fields.related.ManyRelatedManager%20object%20at%200x1067d6050%3E/2012/03/07/1/tropical-twizzler/&#8217;

I would like to get something like this: ‘http://localhost:8000/product/candies/2012/03/07/1/tropical-twizzler/&#8217;

Sorry for being a noob, still learning my way around Django.

  • 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-05-31T00:06:40+00:00Added an answer on May 31, 2026 at 12:06 am

    The problem is category is a ManyToManyField. By definition, directly accessing ManyToManyField does not give you a single value but a set of values, which we call it ManyRelatedManager. In order to pick out a value out of the manager instance, you should be able to figure it out here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am having a problem adding COUNT to my query. the query works fine
i am having a problem in adding the image files to project namespace. I'm
I am a newbee to solr.I am having a problem with adding fields/metadata to
I'm comming from SVN background and I'm having a problem of adding to my
I'm having a strange problem with adding a UINavigationController to my iPhone application. I
I'm having a problem with the new google maps api when adding multiple markers
I'm having a memory problem related to UIImageView. After adding this view to my
I'm having a problem with adding the Qxt library to Qt Designer. The error
I'm having problem with adding style attributes to the control in my custom web
I'm having a problem adding an item to my tableView. I used to initialize

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.