On 9 March 2010 15:22, Forrest Liu <www.forr...@gmail.com> wrote:
> Hi,
> I am struck with this strange error message:
> AttributeError at /products/
>
> 'function' object has no attribute 'objects'
>
> Request Method:GET
> Request URL:http://127.0.0.1:8000/products/
> Exception Type:AttributeError
> Exception Value:
>
> 'function' object has no attribute 'objects'
>
> Exception Location:E:\workspace\biotech\biotech\..\biotech\bio\views.py in
> product, line 35
> my views.py:
> def product(request):
>     products = product.objects.all().order_by('name')
>     return
> object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)
> my model.py:
> class product(models.Model):
>     name = models.CharField(max_length=100)
>     description = models.TextField(blank=True)
>     def __unicode__(self):
>         return self.name
>
> and my index.html is :
> {% for n in object_list %}
> <div class="product">
> <a href="/products/{{n.url}}/">{{n.name}}</a>
> </div>
> {% endfor %}
> my Django version:1.1.1
> python version: 2.6
> Could you be so kind to give me some help,Thank you
> --
>
> Best regards,
> Forrest
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

Rename your model to Product with capital P.

Right now when you say

def product(request):
    products = product.objects.all().order_by('name')

you are calling def product function instead of class product model.


Try something like:

def product(request):
    products = Product.objects.all().order_by('name')
    return 
object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)

class Product(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField(blank=True)
    def __unicode__(self):
        return self.name


Further reading:

http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to