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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:13:02+00:00 2026-06-16T13:13:02+00:00

I have 2 models: class Producer(models.Model): def __unicode__(self): return self.name def get_absolute_url(self): return /prod/%i/

  • 0

I have 2 models:

class Producer(models.Model):
    def __unicode__(self):
            return self.name
    def get_absolute_url(self):
        return "/prod/%i/" % self.id 
    name = models.CharField(max_length=10, unique=True)

class Car(models.Model):
    def __unicode__(self):
            return self.name
    def get_absolute_url(self):
        return "/prod/%s/car/%i" % Producer.id, self.id 
    name = models.CharField(max_length=10, unique=True)
    prod = models.ForeignKey(Producer)

On /sitemap.xml I have an error: type object 'Producer' has no attribute 'id'. How to get in the method get_absolute_url (of Car class) id of the Producer? Thanks. I try Producer_id, Producer__id but it doesn’t works.

  • 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-16T13:13:03+00:00Added an answer on June 16, 2026 at 1:13 pm

    It should be:

    def get_absolute_url(self):
        return "/prod/%s/car/%s" % (self.prod.id, self.id)
    

    Also looking into your code there can be done two more improvements:

    1. Model class method should come after the fields
    2. You should use reverse-resolution-of-urls instead of hard coding the url /prod/%s/car/%s which is a bad way to do.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

model: class Store(models.Model): name = models.CharField(max_length = 20) class Admin: pass def __unicode__(self): return
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have the following model structure below: class Master(models.Model): name = models.CharField(max_length=50) mounting_height =
I have the following two models: class Shelf < ActiveRecord::Model has_many :wines def self.order_by_oldest_bottle_of_wine
Let's say I have some contrived models: class Author(Model): name = CharField() class Book(Model):
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
Let's say I've defined this model: class Identifier(models.Model): user = models.ForeignKey(User) key = models.CharField(max_length=64)
I have the following Rails model: class CreateFoo < ActiveRecord::Migration def self.up create_table :foo
I have the following model: class JobApplication(models.Model): profile = models.ForeignKey(UserProfile) job = models.ForeignKey(JobPost) def

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.