On Feb 5, 8:25 am, Grimmo <lord.sau...@gmail.com> wrote:
> Hi,
> I have these models for my application:
>
> class Movie (models.Model):
>         Title = models.CharField(max_length=100)
>         Director = models.CharField(max_length=100,blank=True)
>         Year = models.CharField(max_length=100,blank=True)
>         Backed_up = models.BooleanField(default=True)
>         Seen = models.BooleanField()
>
> class Media(models.Model):
>         MediaNumber = models.PositiveIntegerField(unique=True)
>         MoviesContained =
> models.ManyToManyField
> (Film,related_name="related_support",verbose_name="movies")
>
> And I'd like to have the admin interface list only movies not yet
> backed up(i.e. Backed_up == False) when I add a new Media object. At
> present, I have to choose from all Movie objects when I add the
> foreign key to the Media.
> Is it possible to do that without using javascript tricks and how?

Try the limit_choices_to attribute on your M2M field:

MoviesContained = models.ManyToManyField(Film,
related_name="related_support", verbose_name="movies",
limit_choices_to={'Backed_up':False})

http://docs.djangoproject.com/en/dev//ref/models/fields/#manytomanyfield

-RD

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