gen_certi
variable is a queryset (list of objects), because you are using filter()
- use get()
instead:
gen_certi = Certificate.objects.get(pk = kwargs.get('cert_id')).generic_certificate
Actually, I don't understand what are you planning to do in the view. If you are modifying the object, there is no need to overwrite the existing fields, just update the fields that are passed to the view in request.POST
, like position:
try:
certificate = Certificate.objects.get(pk = kwargs.get('cert_id'))
certificate.position = request.POST.get('hid')
certificate.save()
except DoesNotExist:
# create new certificate
certificate = Certificate()
...
Hope that helps.