Yes, clear. Thanks.

I read that example (found here:  
http://www.djangoproject.com/documentation/models/many_to_one/
) right after I posted.

I thought this usage made it very clear:
# Create an Article via the Reporter object.
>>> new_article = r.article_set.create(headline="John's second story", 
>>> pub_date=datetime(2005, 7, 29))
>>> new_article
<Article: John's second story>
>>> new_article.reporter.id
1

I'm curious about the use of instance.<item>_set. If I have models:

class Foo(models.Model):
  # something

class Bar(models.Model):
  myFoo = models.ForeignKey(Foo)

...would I be able to say barInstance.myFoo_set.[] ?

Thanks,
Ivan

On Jul 6, 11:59 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote:
> On 7/6/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > class content(model.Models):
> >   link = models.URLField(verify_exists=True)
> >   mods = models.SomeKindOfManyToOne(lotsOfMods)
>
> Both in the database and in Django's ORM, it's done the other
> direction.  What you're looking for is called a foreign key
> (ForeignKey in Django).
>
> Let's take the Article / Reporter models as an example.  An article
> has one reporter, but a reporter can have more than one article.
>
> To model this in the database, we make a reporter table with a primary
> key-- that's a value that uniquely identifies the reporter record.
>
> In the article table, we make a foreign key to the reporter's primary key.
>
> reporter table:
> id   name
> 1    joe
> 2   lisa
>
> article table
> id  reporter_id title
> 1   1             "spamalot rocks"
> 2   2             "sushi sundae"
> 3   1             "ratatouille smoothies"
>
> ----
>
> From these records, we see that joe and lisa are reporters, and that
> "spamalot rocks" and "ratatouille smoothies" are articles written by
> joe, while "sushi sundae" was written by lisa.
>
> In the Django Model definition, it's like this:
>
> class Reporter(models.Model):
>     name = models.CharField(maxlength=50)
>
> class Article(models.Model):
>     reporter = models.ForeignKey(Reporter)
>    title = models.CharField(maxlength=50)
>
> Clear?


--~--~---------~--~----~------------~-------~--~----~
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