Potential redundancy: Device.currentlending vs Device.lending_set
The "Device" model currently has an 1:n relationship with Lending. A Lending concerns exactly one device, but a Device saves all of its previous lendings as well.
To get the current lending, there currently is another field in the Device model that is called Device.currentlending
.
Right now, whenever a lending is created, both have to be updated in the code. This seems like a big source of potential errors.
Example from the DeviceLend class, simplified:
lending = Lending()
...
oldlending = device.currentlending
oldlending.returndate = datetime.date.today()
oldlending.save()
...
device.currentlending = lending
device.save()
lending.device = device
lending.save()