invalid attribute

40 views
Skip to first unread message

ngangsia akumbo

unread,
Jul 31, 2014, 5:48:55 PM7/31/14
to django...@googlegroups.com
Got an invalid attribut error

class Product(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField(max_length=255, unique=True,
            help_text="Each product has a unique name")
    brand = models.CharField(max_length=50)
    sku = models.CharField(max_length=50)
    price = models.DecimalField(max_length=9, decimal_places=3)
    old_price = models.DecimalField(max_length=9, decimal_places=3, blank=True, default=0.00)
    image = models.CharField(max_length=50)
    is_active = models.BooleanField(default=True)
    is_bestseller = models.BooleanField(default=False)
    is_featured = models.BooleanField(default=False)
    quantity = models.IntegerField()
    description = models.TextField()
    meta_keywords = models.CharField('Meta Keywords', max_length=300)
    meta_description = models.CharField("Meta Description", max_length=255)
       
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    category = models.ManyToManyField(Category)


    class Meta:
        db_table = 'products'
        ordering = ['-created_at']

        def __unicode(self):
            return self.name


        @models.permalink
        def get_absolute_url(self):
            return ('catalog_product', (), { 'product_slug': self.slug })

       
        def sale_price(self):
            if self.old_price > self.price:
                return self.price
            else:
                return None

       
   

cmawe...@gmail.com

unread,
Jul 31, 2014, 10:10:40 PM7/31/14
to django...@googlegroups.com
Do you have the full error message?

ngangsia akumbo

unread,
Aug 1, 2014, 6:55:10 AM8/1/14
to django...@googlegroups.com
class Meta invalid attribute , price_sale, get_absolute_url

Daniel Roseman

unread,
Aug 1, 2014, 7:40:25 AM8/1/14
to django...@googlegroups.com
On Friday, 1 August 2014 11:55:10 UTC+1, ngangsia akumbo wrote:
class Meta invalid attribute , price_sale, get_absolute_url


You *have* to do better than this. As I have told you before, you must provide *all* the relevant information if you want people to help you.

Put yourself in our position. Can you imagine answering your question with the information you have provided so far? It is completely impossible. To start off with, you didn't even bother to say what the error was. When cmawe asked you for the full error message, you didn't cut and paste the actual error, but replied with this incomprehensible snippet.

*What* was the error? Where did it happen? What did Django say? What does this have to do with "class Meta"? How can the error be "price_sale" when you don't use that name in your code anywhere?

If you can provide the information, we can help you. Otherwise, we can't.
--
DR.

Collin Anderson

unread,
Aug 1, 2014, 8:40:14 AM8/1/14
to django...@googlegroups.com
all of your methods are indented too much. They should be at the same level as `class Meta`, not part of it.

ngangsia akumbo

unread,
Aug 2, 2014, 6:22:30 AM8/2/14
to django...@googlegroups.com
That is the error i got ,

i am using windows so it id diffiult at times to copy the full error

ngangsia akumbo

unread,
Aug 3, 2014, 12:03:20 AM8/3/14
to django...@googlegroups.com

i migrated to linux
everything is clear
thanks
Reply all
Reply to author
Forward
0 new messages