Re: Binding a ModelForm to an existing instance

2016-09-05 Thread Vadim Serdiuk
Hi Carlos. At first you should get an article, then put it to the form via instance parameter. If article is not found, instance is None. Than if form is valid, method 'save' creates new object or updates old one. if request.method == 'POST': try: article = Article.objects.get(url=

Binding a ModelForm to an existing instance

2016-09-04 Thread Carlos Mermingas
I have a ModelForm: class ArticleForm(forms.ModelForm): class Meta: model = Article fields = ['url',] The Article model has a url field which is unique. I want users to enter a URL. If the Article already exists, it gets reused. Otherwise, a new instance is created. An