On Mon, Oct 27, 2008 at 7:19 PM, Michael Meier <[EMAIL PROTECTED]>wrote:

>
> Hello
>
> I'm relatively new to Django and I was able to set up a small
> application without any problems, BUT:
>
> How can I access data inside a model that comes from another model. As
> an example, I have a model Person, which has a One-To-Many-
> relationship to Skills. So each person can have multiple skills.
>
> Now my idea is that the Skills model has one function that returns the
> number of skills a person has.
>
> I tried this for several hours now :-(, including searching the
> documentation, but I can't find that information. Maybe I just need a
> push into the right direction.
>
>
You might want to read this section of the docs:

http://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects

It's a little hard to be sure since you did not give specifics on your
model, but assuming you have a model named Person and one named Skill, and
Skill has a ForeignKey field to a Person, then the number of Skills for a
Person instance p would be obtained by:

p.skill_set.count()

So, you don't come at it from the Skill model but rather from an instance of
a Person model.

Karen

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