On Sun, 2007-04-01 at 16:04 -0700, TaMeR wrote:
> > > ===== New Model ======
> > > from data.models import Data
> >
> > > class Route(models.Model):
> > >     #wday =
> > > models.ManyToManyField(Data.objects.filter(name='weekdays')
> >
> > I'm not sure if this is the line you are trying to get to work, but
> > (apart from the missing closing parenthesis) it has no chance of
> > working. You supply a model to ManyToManyFields, not a queryset. It also
> > wouldn't do what you expect in any case because the queryset would be
> > evaluated exactly once at import time and never again, which isn't going
> > to be very dynamic.
> >
> > Regards,
> > Malcolm
> 
> Yes this is exactly the line I am working on
> I don't understand what you mean with dynamic.

I meant that it wouldn't be up to date -- even if it did what you
expected, it would only have the value that was computed at import time,
which may not be the same as the value when you want to view the
options. The major benefit of linking to another database table is
because the data in the other table may change -- otherwise you could
just hard-code the values -- normally you would want to reflect that
changing data in your views.

> I am trying to limit the choices in the ManyToManyFields with an sql
> query. Something like this:
> SELECT `id`, `name`  FROM `data_data` WHERE `name` = 'weekdays'
> 
> So that only weekdays will be available in the Select box.

Well, you could use the 'choices' attribute (see [1]) and construct the
value dynamically (as in [2]). What you can't do is make up you own
syntax for the ManyToManyField and passing it a queryset for the first
argument is not something that is permitted. The first argument has to
be the model that the relation links to.

Normally, for completely unchanging data fields such as days of the
week, you wouldn't use a separate database table. Just use a list of
choices. You won't lose any flexibility by assuming that there are
always going to be seven days in a week and hard-coding the list of
choices.

[1] http://www.djangoproject.com/documentation/model-api/#choices 
[2]
http://www.pointy-stick.com/blog/2007/03/26/django-tips-variable-choice-lists/

Regards,
Malcolm


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