Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a convenience method for getting the pk name so as not to expose

internals
  • Loading branch information...
commit 023d481199d6cea7d1ca223e3e46535496a81368 1 parent 04dace3
Charles Leifer authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 peewee.py
7 peewee.py
View
@@ -2740,8 +2740,8 @@ def get_or_create(cls, **query):
def get(cls, *args, **kwargs):
return cls.select().get(*args, **kwargs)
- def get_pk_dict(self):
- return {self._meta.pk_name: self.get_pk()}
+ def get_pk_name(self):
+ return self._meta.pk_name
def get_pk(self):
return getattr(self, self._meta.pk_name, None)
@@ -2750,6 +2750,9 @@ def set_pk(self, pk):
pk_field = self._meta.fields[self._meta.pk_name]
setattr(self, self._meta.pk_name, pk_field.python_value(pk))
+ def get_pk_dict(self):
+ return {self.get_pk_name(): self.get_pk()}
+
def save(self, force_insert=False):
field_dict = self.get_field_dict()
if self.get_pk() and not force_insert:
Please sign in to comment.
Something went wrong with that request. Please try again.