On 8/22/05, Brant Harris <[EMAIL PROTECTED]> wrote:
> 
> I agree that it seems odd that Django would, in effect, force it's
> ways upon you.  But Django has been developed under a philosophy of
> adding functionality only if there is a solid use-case for it.  So if
> you can conjure up a model that is a. usefull, and b. cannot be
> implemented using the current Django ORM, then please post here,
> because I would be very interested in seeing it.
> 

I think your way of implementing the model within Django is definitely
better than mine, because mine doesn't, well, work. :)

But it still seems to me that your model is a workaround. If you
change your rel_name for the ManyToManyField to employees and the
related_name to employed_in then you're essentially talking about the
same structure as mine. If you wanted to add the constraint 'an
employee may only be employed in one department' then you'd have to
add code to ensure that the many-to-many relationship wasn't actually
many-to-many. I'd prefer to have that declared in the model (and in
the database), rather than have a pre-save trigger to validate it.

Given that your model is presumably useful, I don't think my model
with that one extra constraint is especially unusual.

It occurs to me that another way to resolve the circular dependency
issue would be to add items to Employee.fields after creating
Department. Looking at the metaclass, I don't think this would work
straight off - it does lots of work setting up the automagically
created module at class __new__ - but that could be split out so it
could be called separately in an 'extra-for-experts' kind of model
like the one I'm suggesting. Or to use the deferred resolution system
that SqlObject uses. What do you think?

I might try implementing something like that, just to see how tricky it is.

I'm also pretty sure that we've strayed away from the original
problem, so I might have a play with this and then start a new thread.
Thanks Brant - it's been interesting, and prompted me to have a bit of
a look at Django's internals.

Cheers,
xtian

Reply via email to