python - How to add many to one relationship with model from external application in django -
my django project uses django-helpdesk app. app has ticket
model.
my app got client
model, should have 1 many relationship ticket- example list tickets concerning specific client.
normally add models.foreignkey(client)
ticket
it's external app , don't want modify (future update problems etc.).
i wold have no problem manytomany
or onetoone
don't know how manytoone
(many tickets external app 1 client app)
even more hacky solution: can following in module level code after client
class:
class client(models.model): ... client = models.foreignkey(client, related_name='tickets') client.contribute_to_class(ticket, name='client')
i haven't tested (i didn't actual database migrations), correct descriptors (reversesinglerelatedobjectdescriptor
ticket
, foreignrelatedobjectsdescriptor
client
) added class, , south recognizes new fields. far seems work regular foreignkey
.
edit: not hacky. how django sets foreign keys across classes. reverses process adding field when reverse related class built. won't raise error if of original fields on either model shadowed. make sure don't that, potentially break code. other that, don't think there should issues.
Comments
Post a Comment