I have a function called get_urls that returns a list of absolute_urls
for various models in the same project.  This function is used for
another model in a way so that when a particular model appears on the
site, I can choose which part of the site this model links to.

# utils.py
def get_urls():
  urls = []
  for flatpage in FlatPage.objects.order_by('title')
    urls.append(flatpage.url, '%s: %s' % ('Flatpage',
flatpage.title),))
  return urls

There are more objects, this is just a sample with the well-known
FlatPage model.

The particular model I use this with looks like this:

# models.py
from utils import get_urls
class BannerImage(models.Model):
  image = models.ImageField(etc)
  url = models.CharField(max_length=100, choices=get_urls())
  etc...

So it turned out that the admin seemed to be caching the choices.  So,
if I added a new flatpage, it would not be listed there until I
restarted the webserver.  So instead of referring to
Flatpage.objects.etc... directly in get_urls, I made a function that
returns the queryset instead:

# utils.py
def get_flatpages():
  return FlatPage.objects.order_by('title')

Problem still seemed to exist.  I tried making a custom ModelForm in
admin.py for this BannerImage model:

# admin.py
from utils import get_urls
class BannerImageForm(forms.ModelForm):
  url = forms.ChoiceField(choices=get_urls())
  class Meta:
    model = BannerImage

  ...etc...

I tested with the Python shell to see if the get_urls function returns
an updated list after a new object and it does.  Its just the admin
that seems to have the problem.  Is there any way I can get this to
work?

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