Skip to content

Instantly share code, notes, and snippets.

@chriskief

chriskief/view.py

Last active Jun 14, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@suhailvs suhailvs commented Jun 14, 2021

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