开发者

Django: ForeignKey() or ManyToMany() in this case? Or, other?

开发者 https://www.devze.com 2022-12-17 17:34 出处:网络
I have a model that is something like this: class ReturnAuthorization(models.Model): custom_id = models.CharField(max_length=40)

I have a model that is something like this:

class ReturnAuthorization(models.Model):
    custom_id = models.CharField(max_length=40)

class RMAAPILog(models.Model):
    return_authorization = models.ForeignKey(ReturnAuthorization)

If I were to delete() a return authorization, I can't have it delete all the RMAAPILog()s that are related to it. In this cas开发者_运维问答e they get deleted. There can be many attempts to get an RMA from the outside API (so many RMAAPILog()s per ReturnAuthorization(), but there can only be one ReturnAuthorization() for each RMAAPILog() of course because it's a log of an attempt to authorize a specific ReturnAuthorization(). What would be the better way to do this, or am I thinking of it all wrong?


Related SO question: How do I create a Django model with ForeignKeys which does not cascade deletes to its children?

0

精彩评论

暂无评论...
验证码 换一张
取 消