Я работаю над проектом, где я взял django в бэкэнд. У меня есть профиль вызова модели, который связан с пользователем. Модель профиля имеет более 10 полей, и при попытке обновить профиль пользователя мой код для обновления всех этих полей будет выглядеть примерно так
class UpdateProfile(graphene.Mutation):
class Arguments:
input = types.ProfileInput(required=True)
success = graphene.Boolean()
errors = graphene.List(graphene.String)
profile = graphene.Field(schema.ProfileNode)
@staticmethod
def mutate(self, info, **args):
is_authenticated = info.context.user.is_authenticated
data = args.get('input')
if not is_authenticated:
errors = ['unauthenticated']
return UpdateProfile(success=False, errors=errors)
else:
profile = Profile.objects.get(user=info.context.user)
profile = models.Profile.objects.get(profile=profile)
profile.career = data.get('career', None)
profile.payment_type = data.get('payment_type', None)
profile.expected_salary = data.get('expected_salary', None)
profile.full_name = data.get('full_name', None)
profile.age = data.get('age', None)
profile.city = data.get('city', None)
profile.address = data.get('address', None)
profile.name_of_company = data.get('name_of_company', None)
profile.job_title = data.get('job_title', None)
profile.zip_code = data.get('zip_code', None)
profile.slogan = data.get('slogan', None)
profile.bio = data.get('bio', None)
profile.website = data.get('website', None)
profile.github = data.get('github', None)
profile.linkedin = data.get('linkedin', None)
profile.twitter = data.get('twitter', None)
profile.facebook = data.get('facebook', None)
profile.image=info.context.FILES.get(data.get('image', None))
profile.save()
return UpdateProfile(profile=profile, success=True, errors=None)
Итак, мой вопрос, предположим, если бы было более 20, 30 полей, как бы вы разработали свой код для обновления этих полей? (учитывая только часть просмотров)