I am fairly new to Django and I think I pretty much get the basic idea of ORM. However, there is a peculiar situation to which I do not see a plausible solution. I have a legacy database for which I am trying to write a Django app. The sql structure of both the tables is:
mysql> describe event; +-----------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+-------+ | sid | int(10) unsigned | NO | PRI | NULL | | | cid | int(10) unsigned | NO | PRI | NULL | | | signature | int(10) unsigned | NO | MUL | NULL | | | timestamp | datetime | NO | MUL | NULL | | +-----------+------------------+------+-----+---------+-------+ mysql> describe alerts; +----------------+-----------+------+-----+------------------- +----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+-----------+------+-----+------------------- +----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | sid | int(11) | YES | MUL | NULL | | | cid | int(11) | YES | | NULL | | | confidence | int(11) | YES | | NULL | | | cvss_base | float | YES | | NULL | | | composite_conf | float | YES | | NULL | | +----------------+-----------+------+-----+------------------- +----------------+ The first table cannot be altered because it would break a lot of code (which I have not written). The second table was written by me (hence the surrogate key).In the second ('alerts') table, (sid,cid) is unique. The problem is that (sid,cid) is the key on which tables can be effectively joined. How should the models be re-written so that Django can accurately capture the relation between the two tables? I tried OnetoOne for both sid and cid separately but that is clearly not useful since OnetoOne should apply on (sid,cid) simultaneously. OnetoMany is also of no use and neither is ForeignKey since I need (sid,cid) to be the foreign key. It appears that (sid,cid) composite field should be OnetoOne but I don't know how to achieve that. Note - (sid,cid) value will be of the type 1-55,2-55,3-55,1-56,2-57,3-60 etc. all of which are unique and will have only one entry in both the tables. -- 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.