Correct way to use get_or_create?

后端 未结 5 2116
名媛妹妹
名媛妹妹 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 05:52

    get_or_create() returns a tuple:

    customer.source, created  = Source.objects.get_or_create(name="Website")
    
    • created has a boolean value, is created or not.

    • customer.source has an object of get_or_create() method.

提交回复
热议问题