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=
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
2 matches
Mail list logo