Skip to content

Instantly share code, notes, and snippets.

@chriskief
Last active June 14, 2021 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskief/12e15bedb17385bba0f3 to your computer and use it in GitHub Desktop.
Save chriskief/12e15bedb17385bba0f3 to your computer and use it in GitHub Desktop.
from django.views.generic import UpdateView
from forms import MyModelForm
from models import MyModel
class MyUpdateView(UpdateView):
# specify a custom ModelForm
form_class = MyModelForm
# or simply specify the Model
# model = MyModel
def get_object(self, queryset=None):
# get the existing object or created a new one
obj, created = MyModel.objects.get_or_create(col_1=self.kwargs['value_1'], col_2=self.kwargs['value_2'])
return obj
@suhailvs
Copy link

how to write url.py for both create and update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment