openwisp / django-x509

Reusable django app implementing x509 PKI certificates management
http://openwisp.org
BSD 3-Clause "New" or "Revised" License
340 stars 68 forks source link

use self.pk instead of self.id #67

Closed rtrajano closed 4 years ago

rtrajano commented 4 years ago

Some models don't use an id field. If a model is based off of AbstractCA/Cert and specifies a primary_key field that isn't the default id, Attribute errors will occur in the save method.

Swap self.id for self.pk will still point to id if it's not specified, but will allow for users to use a different PK field.

https://docs.djangoproject.com/en/2.2/ref/models/instances/#django.db.models.Model.pk

In my use case, I want to use the certificate's sha256 fingerprint as the identifier so my urls in my rest API will look like certificate/<fingerprint>.

rtrajano commented 4 years ago

if you apply commit f77ab59 to master and run tests, you will get an attribute error that is fixed by commit e56ff29.

rtrajano commented 4 years ago

addressed feedback