dinoperovic / django-salesman

Headless e-commerce framework for Django and Wagtail.
https://django-salesman.rtfd.io
BSD 3-Clause "New" or "Revised" License
391 stars 48 forks source link

Allow non-integer primary keys #46

Open thenewguy opened 6 months ago

thenewguy commented 6 months ago

The basket serializer expects an Integer primary key for product_id.

From an initial search it looks like this is the only spot requiring Integer primary keys. UUID primary keys are common and for consistency it is nice to use them here.

Please consider adding support for UUID (or more generically, non-integer) primary keys.

Thanks!

thenewguy commented 6 months ago

Also - I would be happy to provide PRs for the issues that I have raised. Please let me know if you will accept suitable PRs for any of them. Thanks!

thenewguy commented 6 months ago

I worked through this. The required changes would be:

The generally useful changes would be:

The documentation changes would be:

from rest_framework.utils.encoders import JSONEncoder

class JSONSerializer: """ Simple wrapper around json to be used in signing.dumps and signing.loads. """ def dumps(self, obj): return json.dumps(obj, separators=(',', ':'), cls=JSONEncoder).encode('latin-1')

def loads(self, data):
    return json.loads(data.decode('latin-1'), cls=JSONEncoder)

So far those seem to be the only required changes.