On Sep 24, 6:07 am, Alvaro Mouriño <alvaro.stev...@gmail.com> wrote: > Hi list. > > I'm developing a news application that handles articles, about 10 new > articles each day. The site administrator every morning selects from a > drop-down-list the ones that hit the front page. As time goes by this > list grows bigger and bigger, and what's worst, old articles doesn't > even matter at all. > > I could sort by creation date and limit the queryset with the > ModelAdmin.formfield_for_foreignkey method. I do both, but it's not > perfect. > > Nowadays I limit the list of articles to only the ones published today > and yesterday. The problem with this is that when editing an instance, > if old enough (more than two days) no articles will show up, not even > the selected one, which as you could imagine makes editing old > instances impossible. > > I'd like to know if there's a way to access an attribute of the > instance in the formfield_for_foreignkey method so I can tell django > to display a list of articles based on the creation date (only the > articles created that day and the day before.) > > (I could use a raw_id_field but it would be a usability problem to not > see the article's title in the same page.) > > Regards, > > -- > AlvAro
This is probably outside the scope of what can be achieved via formfield_for_foreignkey. However it would be possible by defining a custom form and overriding the __init__ method. After calling super(), you can then modify the queryset of the FK field - you would have access to the current instance via self.instance. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---