Matthias Kestenholz wrote:
<snip>
> Is this your complete Membership model? Or do you have additional
> fields there? If you've only got these two foreign keys, it might be
> better to use a many to many field that references the same model (
> ManyToManyField('self') )
Thanks Matthias - exactly what I wanted - see below. It isn't the
complete system but I'm just starting and want to get the beginnings
more or less correctly working.
> Plus, you should use unicode(), not str() inside __unicode__ -- str()
> will bail if client_type or surname contains non-ASCII-chars.
Thanks again ...
Daniel Roseman wrote:
> On Jul 24, 5:46 am, Mike Dewhirst <[email protected]> wrote:
>> I'm new to Django and want to express a self-referencing design
>> feature to link clients in the same table with each other.
<snip>
> You don't say what the error is. I can guess, though, and as always
> the clue is in the error message (why do people never seem to read
> these?)
Thanks also Daniel. You are right of course - my apologies. I did read
the message but did not have the brainspace to understand it at the
time. Even now I'm relying on assumptions which I hope will become clear
one day. Which leads me to another question about Django orm ...
Does Django need to create all the tables itself? I have been dropping
everything and re-syncdb-ing to try and make things happen. Can I make
my own tables and ask Django to use them?
My new models.py is as you and Matthias advised ...
- - - - - - - -
from django.db import models
class Client(models.Model):
""" base class for everyone/thing """
surname = models.CharField(max_length=48, blank=False)
client_type = models.CharField(max_length=24, blank=True)
group = models.ManyToManyField('self',
#db_table='foo_membership',
blank=True)
def __unicode__(self):
return u'%s : %s' % (self.client_type, self.surname)
class Membership(models.Model):
""" cross (xr) referencing and linking clients """
client_x = models.ForeignKey(Client, related_name='x_set')
client_r = models.ForeignKey(Client, related_name='r_set')
description = models.CharField(max_length=48, blank=False)
def __unicode__(self):
return u'Linked: %s - %s' % (unicode(self.client_x),
unicode(self.client_r))
- - - - - - - -
If I reverse the position of the above two classes prior to syncdb,
Django quite reasonably complains that Client (in Membership) does not
exist. If I leave them in the above sequence it invents its own
foo_client_group table for the n:m table and then creates my Membership
table too.
I have tried using db_table='foo_membership' but that causes ...
File "C:\usr\bin\lib\site-packages\django\db\backends\util.py", line
19, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "foo_membership" already exists
I could cope with omitting my Membership table and adding a
'description' column to Django's 'foo_client_group' table - but then how
do I make a class which knows about the foo_client_group table name?
Is there a trick to it or have I (more likely) missed something obvious?
Sorry to be so opaque. I'm just getting over a month of late nights.
Thanks
Mike
<snip>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---