Last active
          June 14, 2021 23:32 
        
      - 
      
 - 
        
Save chriskief/12e15bedb17385bba0f3 to your computer and use it in GitHub Desktop.  
  
    
      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
    
  
  
    
  | 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 | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
how to write
url.pyfor both create and update