Answer the question
In order to leave comments, you need to log in
How to change the date field value correctly?
There is a dynamically generated model.
It works like this:
# ...
# model_cls - динамически сгенерированная модель
class ValidationForm(ModelForm):
class Meta:
model = model_cls
fields = '__all__'
form = ValidationForm(params)
if form.is_valid():
params = form.cleaned_data
model_cls.objects.create(**params).save()
# ...
function func(model_cls, row_id, field_name, field_value):
row = model_cls.objects.get(id = row_id)
row.__setattr__(field_name, field_value)
row.save()
Answer the question
In order to leave comments, you need to log in
Settled on this one:
# ...
class ValidationForm(ModelForm):
class Meta:
model = model_cls
fields = (field_name, )
params = {field_name: field_value}
form = ValidationForm(params)
if form.is_valid():
field_value = form.cleaned_data[field_name]
# ...
row = model_cls.objects.get(id = row_id)
if hasattr(row, field_name):
row.__setattr__(field_name, field_value)
row.save()
# ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question