Skip to content

Commit

Permalink
allow zero pk
Browse files Browse the repository at this point in the history
  • Loading branch information
Lior Chen committed Dec 17, 2014
1 parent fe44706 commit 858f20f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions parler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def _get_translated_model(self, language_code=None, use_fallback=False, auto_cre
except KeyError:
# 2. No cache, need to query
# Check that this object already exists, would be pointless otherwise to check for a translation.
if not self._state.adding and self.pk:
if not self._state.adding and self.pk is not None:
prefetch = self._get_prefetched_translations(meta=meta)
if prefetch is not None:
# 2.1, use prefetched data
Expand Down Expand Up @@ -457,7 +457,7 @@ def _get_translated_model(self, language_code=None, use_fallback=False, auto_cre
# Explicitly set a marker for the fact that this translation uses the fallback instead.
# Avoid making that query again.
local_cache[language_code] = MISSING # None value is the marker.
if not self._state.adding or self.pk:
if not self._state.adding or self.pk is not None:
_cache_translation_needs_fallback(self, language_code, related_name=meta.rel_name)

if lang_dict['fallback'] != language_code and use_fallback:
Expand Down Expand Up @@ -619,7 +619,7 @@ def save_translation(self, translation, *args, **kwargs):
:param args: Any custom arguments to pass to :func:`save`.
:param kwargs: Any custom arguments to pass to :func:`save`.
"""
if not self.pk or self._state.adding:
if self.pk is None or self._state.adding:
raise RuntimeError("Can't save translations when the master object is not yet saved.")

# Translation models without any fields are also supported.
Expand Down

0 comments on commit 858f20f

Please sign in to comment.