[Answer]-Insert QuerySet results in a table in Django

1👍

I like @doniyor’s solution but if you need more control (for example if field names aren’t exactly the same) you could iterate over the fields and possibly make some decisions:

for feature in Feature.objects.filter(product_id = selected_product_id).all():
    selected_feature = SelectedFeature()
    for attr in SelectedFeature._meta.get_all_field_names():
         selected_feature.setattr(attr, feature.getattr(attr))
    selected_feature.save()
👤nima

Leave a comment