On Dec 3, 3:25 pm, Peter Bailey <[EMAIL PROTECTED]> wrote: > I am trying to use ForeignKey data returned from a page and view, and > am having trouble. I am missing something fundamental I think. > > Say I have 2 models > > class TopModel(models.Model): > name = models.CharField(max_length=50) > db_type = models.CharField(max_length=1, choices=STATUS_DBS) > > # and another class with an FK to the above > > class OtherModel(models.Model): > name = models.CharField(max_length=50) > topmodel = models.ForeignKey(TopModel) > > # Form classes for the above are just as follows: > > class TopModelForm(forms.ModelForm): > > class Meta: > model = TopModel > > class OtherModel(forms.ModelForm): > > class Meta: > model = OtherModel > > Anyway, if I go to a page template and view for OtherModel, say the > user selects an fk for TopModel in OtherModel, > I want to get back the actual fk number , e.g, 3, 10, 1, or whatever > from the post dict. I currently do not get a value back for this (or > I am calling it the wrong thing or something). > > I just want the Interger id for the fk that would be in the db). I > want to use this type of access several layers deep in cases, > and this seems like it should be dirt simple (it would be the old > school way), but of course, I am trying to get away from that. > > I have been looking through the docs and things and just confusing > myself > more and more. > > So, can anyone tell me what I am doing wrong or if there is an easy > (and efficient) way to do this, or perhaps point me to a piece of > actual code that does something similar. > > Thanks very much, > > Peter
Sorry, I'm not able to understand what your issue is. What do you mean by 'going to a page template' and 'getting back' an FK? I think you need to explain your use case a bit more. A ModelForm is basically for editing and creating instances of a model. Are you trying to use it for navigation? Maybe an example of your view might help. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---