Hi!

I am going Django (liking it so far), and I seem to hit a wall with  
one of the exercises. It likely because of my unfamiliarity with  
Python, so bear with me, please.

At the end of Hour 6, I got two exercises to do:

1. Create an additional view for the People object that displays the  
Blog contents for a specific Person.
2. Create an URL pattern in the URLConf that collects the Person's ID  
from the URL request and passes it to the view function that you  
created in Exercise .

So this is the code I have so far:

url.py:

from django.conf.urls.defaults import *

details1 = {'opts':('name','email')}
details2 = {'opts':('name','birthday')}
details3 = {'opts':('name','desc','favoriteURL')}
details4 = {'opts':('name','blogs')}

urlpatterns = patterns('iFriends.People.views',
        (r'^$','index'),
        (r'^Info/$','details'),
        (r'^Info/(?P<pID>\d+)/$', 'details'),
        (r'^Contact/(?P<pID>\d+)/$','details', details1),
        (r'^Birthday/(?P<pID>\d+)/$','details', details2),
        (r'^Details/(?P<pID>\d+)/$','details', details3),
        (r'^Blog/(?P<pID>\d+)/$','blog_details', details4), # This is the one  
I have problems with
        
        
)

The view that I created:


def blog_details(request, pID='0', opts=()):

        response = HttpResponse()
        response.write("<HTML><BODY>\n")
        try:
                b = Person.objects.get(id=pID)
                for d in opts:
                                response.write("<li>%s: %s</li>" % (d, 
b.__dict__[d]))
                                        except Blog.DoesNotExist:
                response.write("Blog Not Found")
                
        response.write("</BODY></HTML>")
        return response


These are the models that I am working with:

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

gender_list = (('M','Male'), ('F', 'Female'))
# Create your models here.


class Blog(models.Model):
        title = models.CharField('Title', maxlength=200)
        text = models.TextField('Text', maxlength=2048)

        class Admin:
                pass

class Person(models.Model):
        userID = models.ForeignKey(User, unique=True)
        name = models.CharField('name', maxlength=200)
        birthday = models.DateField('Birthday',blank=True,null=True)
        gender = models.CharField(maxlength=1, choices=gender_list)
        email = models.EmailField('Email', unique=True)
        headshot = models.ImageField(upload_to='img', blank=True)
        favoriteURL = models.URLField('myURL')
        favoriteBooks = models.ManyToManyField('self',blank=True)       
        favoriteMovies = models.ManyToManyField('self',blank=True)      
        desc = models.TextField('Desc',maxlength=500, null=True)
        friends = models.ManyToManyField('self',blank=True)
        blogs = models.ManyToManyField(Blog, blank=True)

        def __str__(self):
                return '%s' % (self.name)

        class Admin:
                pass


I am able to at least pass the parameters, that I know. That said, I  
kept getting this:

AttributeError at /People/Blog/1/
'QuerySet' object has no attribute 'text'

Request Method: GET
Request URL:    http://giggle.org:8000/People/Blog/1/
Exception Type: AttributeError
Exception Value:        'QuerySet' object has no attribute 'text'
Exception Location:     /home/rilindo/iFriends/../iFriends/People/views.py  
in blog_details, line 53





It is possible that I don't have a clear understanding on how to use  
the ManytoManyField, but I could be wrong. At any event, It is  
probably something simple that I am missing.

Help?

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

Reply via email to