Just for the record, you should probably consider using CreateView and 
UpdateView (docs 
<https://docs.djangoproject.com/en/2.1/ref/class-based-views/generic-editing/>) 
if possible. ;)
Here is an example (Stack <https://stackoverflow.com/a/35577906>).

W dniu wtorek, 18 września 2018 14:13:20 UTC+2 użytkownik Django Lover 
napisał:
>
> How i can update model when Key exist else create a new one??
>  
>
> My code is-
>  
> **Form.py**
>
> class UserSettingForm(forms.ModelForm):
>      class Meta:
>            model = StUserSetting
>            fields = ( 'default_language', 'prim_currency', 'number_format'
> , 'decimal_format',
>             'date_format', 'time_format', 'currency_format', 
> 'currency_position', 'financial_year_start', 
>              'week_start', 'estimate_default_tab', 'invoice_default_tab',)
>
> **View.py**
>
>
> class CreateUpadateUserSetting(LoginRequiredMixin, FormView):
>      template_name = 'settings/user_settings.html'
>      form_class = UserSettingForm
>      success_url = '/user/setting/preference/'
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/04b64a7d-5743-458a-8139-96aa0fb969f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to