Wednesday, June 23, 2010

Re: noob syntax question

(Sorry in advance for the brevity and any typos, I am typing this from
my aging Windows Mobile).

It's quite Django-specific actually. If you take a look at
http://docs.djangoproject.com/en/dev/topics/db/queries/ it says,
"Django also creates API accessors for the "other" side of the
relationship -- the link from the related model to the model that
defines the relationship. For example, a Blog object b has access to a
list of all related Entry objects via the entry_set attribute:
b.entry_set.all()."

Hope that clears things up.

Michael Schade
Spearhead Development LLC

On 6/23/10, Sector7B <joe.greenawalt@gmail.com> wrote:
> Hi,
> In the tutorial 1.
>
> It has this:
> # Give the Poll a couple of Choices. The create call constructs a new
> # choice object, does the INSERT statement, adds the choice to the set
> # of available choices and returns the new Choice object. Django
> creates
> # a set to hold the "other side" of a ForeignKey relation
> # (e.g. a poll's choices) which can be accessed via the API.
>
> and gives these examples:
> # Create three choices.
>>>> p.choice_set.create(choice='Not much', votes=0)
> <Choice: Not much>
>>>> p.choice_set.create(choice='The sky', votes=0)
> <Choice: The sky>
>>>> c = p.choice_set.create(choice='Just hacking again', votes=0)
>
> I understand what its doing, but I don't understand where the "_set"
> comes from or where its resolved to.
> Its probably more of a python thing than a django thing, but if
> someone could provide insight, it would be much appreciate.
>
> Thanks,
> -j
>
> --
> 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
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


--
Sincerely,
Michael Schade
www.mschade.me - 815.514.1410

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate