In a model I feed a contenttype form field some initial data to choose
from.

class MenuItem(models.Model):
   CONTENT_TYPE_CHOICES = tuple(get_available_content())
   content_type = models.ForeignKey(ContentType,
choices=CONTENT_TYPE_CHOICES)

The data is provided using the folowing function which returns a tuple
for every stored (in this case) Poll in the form of 13:xxx where xxx is
the poll_id. Just before saving the data I split the two parts in
content_type_id and content_id. Then I want to hand them over to the
corresponding values. This way it must be possible to add some kind of
menu_app to django which works within the admin interface.

def get_available_content():
   available_content_list = [('13','testpoll')]
   from mysite.polls.models import Poll
   polls_list = Poll.objects.all().order_by('-question')
   for poll in polls_list:
      key = '13:%s' % poll.id
      caption = poll.question
      poll_tup = ( key, caption )
      available_content_list.append(poll_tup)
   return available_content_list

The only thing I can't get working is setting the new value befor
saving

content_type_id, object_id = self.content_type_id.split(':', 1)
self.content_type.id = int(content_type_id)
self.object_id = int(object_id)

Maybe someone has an idea???


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