Hi,
class Category(meta.Model):
name = meta.CharField(maxlength=255)
class Article(meta.Model):
title = meta.CharField(maxlength=255)
category = meta.ForeignKey(Category)
class Pillar(meta.Model):
name = meta.CharField(maxlength=255)
categories =
meta.ManyToManyField(Category,blank=True,filter_interface=me
ta.HORIZONTAL)
articles =
meta.ManyToManyField(Article,blank=True,filter_interface=met
a.HORIZONTAL,limit_choices_to
= {'category__id__in':[1,2,3]})
class META:
admin = meta.Admin()
def __repr__(self):
return self.name
This works great I'm just wondering if there is a way to
change the
value of 'limit_choices_to' after the object has been
created e.g.
1. user chooses certain categories and saves the pillar
2. user edits the pillar again and the list of articles
contains only
articles for the categories selected in that pillar?
I know I can change the value of
p = Pillar(...)
p._meta.many_to_many[1].rel.limit_choices_to = {blah:blah}
at run-time I'm just wondering if there is a way to do it
right after
the object has been created.
perhaps some kind of post __init__ hook or something.
Am I making any sense?
Thanks for help
|