On Sunday, March 27, 2011 02:32:15 pm Dilan wrote:
> Hi All,
> 
> I'm working on a model similar to
> http://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-on-many
> -to-many-relationships .
> 
> Say, I need to add the field, groups = models.ManyToManyField(Group,
> through='Membership') to Person class
> 
> Two questions:
> 1. In Django, is this allowed?

Yes.  But you'll want to have a unique related_name also, iirc.

> 2. In Python, how do you forward declare Group class for this code to
> work?
> 

This isn't really a python way but a django way [1]

ManyToManyField('Group', ...)

In python you can't forward declare outside of the module the object is in. 
there is no equivalent to Class Test; as in c++. (you can dynamically import 
with the imp module though but this isn't forward declaring).

Django models load in such a way that it doesn't know modules that come after 
it in the same module/file and this was to address that.

scroll down just a tad on the link below to get info on the related_name 
attribute.

HTH,

Mike

[1] http://docs.djangoproject.com/en/1.3/ref/models/fields/#lazy-relationships
-- 
Adults die young.

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

Reply via email to