Correct way to use get_or_create?

后端 未结 5 2103
名媛妹妹
名媛妹妹 2020-12-02 05:22

I\'m trying to use get_or_create for some fields in my forms, but I\'m getting a 500 error when I try to do so.

One of the lines looks like this:

cus         


        
5条回答
  •  -上瘾入骨i
    2020-12-02 05:51

    Following @Tobu answer and @mipadi comment, in a more pythonic way, if not interested in the created flag, I would use:

    customer.source, _ = Source.objects.get_or_create(name="Website")
    

提交回复
热议问题