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 <[email protected]> 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 <[email protected]> wrote:
>
>
>
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a...
>
> > Good luck!
>
> > -ld
>
> > On Aug 21, 3:49 pm, goobee <[email protected]> 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 -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---