Created
September 29, 2011 00:54
-
-
Save SmileyChris/1249734 to your computer and use it in GitHub Desktop.
AddOrEditView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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