an ideea:
build a custom Model Form for Character, and after that define CharacterHome
Model Form.

class CharacterForm(forms.ModelForm):
    class Meta:
        model = Character
        exclude = ('some', 'fields','here', 'that', 'you', 'do', 'not',
'want', 'to', 'display' )

class CharacterHomeForm(forms.ModelForm):
    class Meta:
        model = CharacterHome
        exclude = ('character',)

If you want to display them, you just use


obj = CharacterHome.objects.get() # whatever you get your object

chform = CharacterHome(instance=obj)
cform = Character(instance= obj.character)

the rest, should be fun.

Alecs


On Tue, Aug 25, 2009 at 1:14 PM, goobee <goo...@hispeed.ch> wrote:

>
> Hi Léon,
> it's not that basic. Picking up your example, I define a Form based on
> CharacterHome. Then I show 1 entry from CharacterHome; the field
> 'character' is shown as a MultipleChoiceField where ALL entries from
> Character are listed. But I need only the one particular record that
> ist referenced by the selected CharacterHome.
> In addition the user should only get non-editable fields on the html-
> page
>
> regards
> goobee
>
> On 24 Aug., 12:11, Léon Dignòn <leon.dig...@gmail.com> wrote:
> > Basically you have to link them with a foreign key. I hope this fits
> > your needs with the legacy table.
> >
> > class Character(models.Model):
> >     guid = models.IntegerField(primary_key=True)
> >     name = models.CharField()
> >     …
> > class CharacterHome(models.Model):
> >     character = models.ForeignKey(Character, primary_key=True)
> >     …
> >
> > If you want an instance of character returning the guid, define a
> > __unicode__() function
> >
> > def __unicode__(self):
> >     return self.guid
> >
> > -ld
> >
> > On Aug 22, 9:36 pm, Ryan Bales <thinkt...@gmail.com> wrote:
> >
> > > I have experienced this same issue, and that link didn't really help.
> > > I am trying to hook into a legacy database using "inspectdb", and I
> > > can't index the tables.
> >
> > > class Character(models.Model):
> > >      guid = models.IntegerField(primary_key=True)
> > >      name = models.CharField()
> > >      ...
> > >      ...
> > > class CharacterHome(models.Model):
> > >      character = models.IntegerField(primary_key=True)
> > >      ...
> > >      ...
> >
> > > Even though django accurately assesses the datatypes of these tables,
> > > I want to be able to set CharacterHome.character as a ForeignKey
> > > (Character) and have Character return the "guid" integer value.
> >
> > > On Aug 22, 5:29 am, Léon Dignòn <leon.dig...@gmail.com> wrote:
> >
> > > >
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a...
> >
> > > > Good luck!
> >
> > > > -ld
> >
> > > > On Aug 21, 3:49 pm, goobee <goo...@hispeed.ch> wrote:
> >
> > > > > hi there
> >
> > > > > I'm in dire need of a good idea. django drives me crazy with its
> > > > > foreignkey-resolver.
> >
> > > > > class person(models.Model):
> > > > >     name ...
> > > > >     firstname ....
> > > > >     ....
> > > > >     ....
> >
> > > > > class participant(models.Model):
> > > > >     group ......
> > > > >     person(foreignkey(person))
> > > > >     funk ...
> >
> > > > > I want to show 'participant' using the ModelForm-feature. From
> model
> > > > > 'person' I need name and firstname only (or __unicode__) of the
> > > > > particular participant, but django delivers the entire table
> 'person'
> > > > > which is an unnecessary overkill (especially with several FKs in
> > > > > 'participant'). There must be an option to avoid this behaviour!?
> >
> > > > > thanks for any ideas- Hide quoted text -
> >
> > > - Show quoted text -
> >
>


-- 
As programmers create bigger & better idiot proof programs, so the universe
creates bigger & better idiots!
I am on web:  http://www.alecslupu.ro/
I am on twitter: http://twitter.com/alecslupu
I am on linkedIn: http://www.linkedin.com/in/alecslupu
Tel: (+4)0748.543.798

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

Reply via email to