Re: Limiting queryset on ModelAdmin based on date field
On Thu, Sep 24, 2009 at 2:52 AM, Brian McKeeverwrote: > > I'm not too familiar with customizing the admin, but you want to use > the range field lookup. > > http://docs.djangoproject.com/en/dev/ref/models/querysets/#range Thanks McKeever, but that's actually the problem: I don't know the date the instance was created, so I don't know which range to ask for. -- AlvAro --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Limiting queryset on ModelAdmin based on date field
On Thu, Sep 24, 2009 at 6:19 AM, Daniel Rosemanwrote: > > On Sep 24, 6:07 am, Alvaro Mouriño 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. I'll take a look at that. Thanks! -- AlvAro --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Limiting queryset on ModelAdmin based on date field
On Sep 24, 6:07 am, Alvaro Mouriñowrote: > 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 -~--~~~~--~~--~--~---
Re: Limiting queryset on ModelAdmin based on date field
I'm not too familiar with customizing the admin, but you want to use the range field lookup. http://docs.djangoproject.com/en/dev/ref/models/querysets/#range On Sep 23, 11:07 pm, Alvaro Mouriñowrote: > 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 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Limiting queryset on ModelAdmin based on date field
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 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---