Python 无法分配\";(<;公司:Waft公司>;,)\";:\&引用;商业模式。公司\“;必须是\";公司\“;实例

Python 无法分配\";(<;公司:Waft公司>;,)\";:\&引用;商业模式。公司\“;必须是\";公司\“;实例,python,django,django-models,django-views,graphene-python,Python,Django,Django Models,Django Views,Graphene Python,我正在尝试更新商业模式。然而,我得到了一个错误 无法分配\“(,)\”:\“BusinessModel.company\”必须是\“company”实例 我相信,我正在使用company实例保存到以下公司,因为company是FK inBusinessModel 公司不是一个公司实例吗?下面是获取实例的助手函数 def get_instance(_object, encoded_id, slug=False, otherwise=None): try: if slug:

我正在尝试更新商业模式。然而,我得到了一个错误

无法分配\“(,)\”:\“BusinessModel.company\”必须是\“company”实例

我相信,我正在使用company实例保存到以下公司,因为company是FK in
BusinessModel

公司不是一个公司实例吗?下面是获取实例的助手函数

def get_instance(_object, encoded_id, slug=False, otherwise=None):
    try:
        if slug:
            return _object.objects.get(slug=encoded_id)
        else:
            return _object.objects.get(pk=from_global_id(encoded_id)[1])
    except _object.DoesNotExist:
        return otherwise
这就是我所做的

class BusinessModel(models.Model):

    ZERO = '0'
    ONETOFIFETYTHOUSAND = '1 - 50000'
    FIFETYTHOUSANDTOONELAKH = '50000 - 1Lakhs'

    TOTAL_INVESTMENT = (
        (ZERO, '0'),
        (ONETOFIFETYTHOUSAND, '1 - 50000'),
        (FIFETYTHOUSANDTOONELAKH, '50000 - 1Lakhs'),
    )
    FRANCHISE_FEE = TOTAL_INVESTMENT
    company = models.ForeignKey(Company, related_name='company_business_model', on_delete=models.CASCADE)
    industry = models.ForeignKey(Industry, null=True, related_name='industry', on_delete=models.SET_NULL)
    segments = models.ForeignKey(Segment, on_delete=models.SET_NULL, null=True)
    total_investment = models.CharField(max_length=50, choices=TOTAL_INVESTMENT, default=None)
    franchise_fee = models.CharField(max_length=50, choices=FRANCHISE_FEE, default=None)
    is_refundable = models.BooleanField(default=False)
    space = models.CharField(max_length=50, blank=False, null=False, help_text="space in square feet")  # choice field


class BusinessModelInput(graphene.InputObjectType):

    company = graphene.String()
    industry = graphene.String()
    segments = graphene.String()
    total_investment = graphene.String()
    franchise_fee = graphene.String()
    is_refundable = graphene.String()
    space = graphene.String()
    expanding_country = graphene.String()
    expanding_city = graphene.String()
    expanding_regions = graphene.String()


class UpdateBusinessModel(graphene.Mutation):

    class Arguments:

        input = BusinessModelInput(description="These fields are required", required=True)
        id = graphene.String(description="Id of business model", required=True)

    class Meta:

        description = "Update Business Model Mutation"

    errors = graphene.String()
    business_model = graphene.Field(BusinessModelNode)

    @staticmethod
    def mutate(root, info, **args):
        if not info.context.user.is_authenticated:
            return UpdateBusinessModel(errors=json.dumps('Please Login to list your brand'))
        try:
            print('args', args.get("id"))
            business_model_instance = get_instance(models.BusinessModel, args.get('id'))
            company = get_instance(models.Company, args.get('input')['company'], slug=True)
            print("company", company)
            industry = models.Industry.objects.get(slug=args.get('input')['industry'])
            segment = models.Segment.objects.get(slug=args.get('input')['segments'])
            if business_model_instance and company and industry:
                business_model_instance.company = company,
                business_model_instance.industry = industry,
                business_model_instance.segments = segment,
                business_model_instance.total_investment = args.get('input')['total_investment'],
                business_model_instance.franchise_fee = args.get('input')['franchise_fee'],
                business_model_instance.is_refundable = args.get('input')['is_refundable'],
                business_model_instance.space = args.get('input')['space'],
                print('business_model instance', business_model_instance)
                business_model_instance.save()
                return UpdateBusinessModel(business_model=business_model_instance, errors=None)
        except (models.BusinessModel.DoesNotExist, models.Company.DoesNotExist, models.Industry.DoesNotExist, models.Segment.DoesNotExist):
            return UpdateBusinessModel(errors=json.dumps('Company should be required'))

为什么我会出错

每个赋值后都有逗号,可以将值转换为元组。移除它们

business_model_instance.company = company  # no comma

看起来
encoded\u id
是公司的单元组的
repr(..)
str(..)
的结果,而不是公司的引用。如何调用上述函数,请提供完整的回溯。我犯了一个多么愚蠢的错误。非常感谢你的帮助。这似乎是一个愚蠢的错误,但却浪费了我相当多的时间。