Skip to content

Instantly share code, notes, and snippets.

@earthling-shruti
Last active December 22, 2015 08:08
Show Gist options
  • Save earthling-shruti/6442618 to your computer and use it in GitHub Desktop.
Save earthling-shruti/6442618 to your computer and use it in GitHub Desktop.
class Model1(models.Model):
pass
class Model2(models.Model):
model1 = OneToOneField('Model1')
====================================
class myView(UpdateView):
...
def get_context_data(self, **kwargs):
model1 = Model1.objects.get(pk=self.pk_url_kwargs)
model2, created = Model2.objects.get_or_create(model1=model1)
return model2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment