Skip to content

Instantly share code, notes, and snippets.

@SmileyChris
Created September 29, 2011 00:54
Show Gist options
  • Save SmileyChris/1249734 to your computer and use it in GitHub Desktop.
Save SmileyChris/1249734 to your computer and use it in GitHub Desktop.
AddOrEditView
class AddOrEditView(generic.UpdateView):
# The following two _kwarg attributes are introduced in Django 1.4, until
# then, they can exist here without any concern.
slug_url_kwarg = 'slug'
pk_url_kwarg = 'pk'
def get_object(self, *args, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg)
slug = self.kwargs.get(self.slug_url_kwarg)
if pk is None and slug is None:
return None
return super(AddOrEditView, self).get_object(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment