This isn't valid Python. It looks like a cross between defining a
function and defining a class.
> word = models.ManyToManyField(Word)
This isn't valid. Model field belong in models, not functions. I suspect
you've just made a typo and typed "def" above when you meant "class". If
you've actually mentioned what the error you were seeing was (or read it
carefully), I suspect that Python would have told you basically that.
> stats = ...
>
> Is there anyway to accomplish this? Without writing separate models
> for each word.
A many-to-many field to the Word model is an appropriate approach.
Regards,
Malcolm
One of the many problems with top-posting is that I can't tell what
you're replying to. So I need to guess. I guess that "that was a typo"
is where you used "def" instead of "class"..
> > On Sat, 2008-11-15 at 06:57 -0800, Luke Seelenbinder wrote:
> > > Basically, I want to allow a ManyToManyField to use any of a Model's
> > > children, like this:
> >
> > > class Word(models.Model):
> > > word = models.CharField(...)
> >
> > > class Meta:
> > > abstract = True
You can't do what you're trying to do in that fashion (using
ManyToManyField to an abstract base class). Many-to-many and foreign-key
relations are relations between one table to another table, not to many
other tables. They model the database's idea of relations. That's why
they aren't allowed to be declared for abstract models (which aren't
really models at all).
You could, however, model this using an intermediate table with generic
relations, which allows links to multiple types of remote models through
a content-type field. You won't be able to use anything like "through",
but that's really just a kind of syntactic sugar anyway. You can write
the same sorts of queries referring to the intermediate model
explicitly.
Regards,
Malcolm
On Sun, Nov 16, 2008 at 4:13 AM, Malcolm Tredinnick
<mal...@pointy-stick.com> wrote:
>
> You can't do what you're trying to do in that fashion (using
> ManyToManyField to an abstract base class). Many-to-many and foreign-key
> relations are relations between one table to another table, not to many
> other tables. They model the database's idea of relations. That's why
> they aren't allowed to be declared for abstract models (which aren't
> really models at all).
>
> You could, however, model this using an intermediate table with generic
> relations, which allows links to multiple types of remote models through
> a content-type field. You won't be able to use anything like "through",
> but that's really just a kind of syntactic sugar anyway. You can write
> the same sorts of queries referring to the intermediate model
> explicitly.
As I'm concerned by the same problem (refering by a ForeignKey to an
abstract class) and don't want to make my abstract class concrete, I'm
interested in the solution you talk about.
Can you explain me more what do you think about, I don't really
understand how I can do that?
Thanks in advance.
--
Eric Veiras Galisson
http://www.veiras.info