This thread has slipped into inactivity, but perhaps there is someone, who can clear this thing for me.
Additionally... with form = articleForm(instance=i) it does insert new article into database instead of updating old one... Alan. On May 9, 10:27 pm, zayatzz <alan.kesselm...@gmail.com> wrote: > Thanks for the advice- it worked like a charm and i guess that was the > better way to do it. > > But lets say i do need to create new item into database - new revision > of an edited article. In that case the code i posted previously should > work, or should it not? And why does'nt it work? > > Alan > > On May 9, 9:30 pm, Daniel Roseman <roseman.dan...@googlemail.com> > wrote: > > > On May 9, 1:24 pm, zayatzz <alan.kesselm...@gmail.com> wrote: > > > > Hello > > > > I've been trying to figure out how to use modelforms and so far ive > > > managed to do things on my own. But now im trying to prepopluate > > > modelform and it does not work - not completely anyway. > > > > Model: > > > from django.db import models > > > from tinymce import models as tinymce_models > > > > class article(models.Model): > > > name = models.CharField(max_length=200) > > > content = tinymce_models.HTMLField() > > > > Form: > > > from django.db import models > > > from django import forms > > > from mce.arts.models import article > > > from tinymce.widgets import TinyMCE > > > from django.forms import ModelForm > > > > class articleForm(ModelForm): > > > content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, > > > 'rows': > > > 30})) > > > class Meta: > > > model = article > > > > view: > > > i = article.objects.get(id=4) > > > initial_dict = { > > > 'name': i.name, > > > 'content':i.content, > > > } > > > form = articleForm(initial=initial_dict) > > > Result is that first field is filled but the 2nd is not. It is not > > > problem of tinymce scripts, because if i remove the editor scripts > > > from view then i just get an empty textfield. > > > > There are several resuts if i search the web about prepopulating model > > > fields, but none of them is about such problem. For prepopulating > > > itself i followed this thread as an example > > > :http://groups.google.com/group/django-users/browse_thread/thread/ff83... > > > > Alan > > > Since articleForm is a ModelForm, you'd be best off using the instance > > parameter rather than initial when you instantiate the form. That way, > > it will also get the correct model ID, so that calling save() on the > > form will correctly update the database rather than inserting a new > > item. > > > form = articleForm(instance=i) > > > (Also, note that the Python convention is to use InitialCaps not > > camelCase for class names, so it should be ArticleForm and Article. > > But that's just being picky.) > > -- > > DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---