On Sep 21, 3:25 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Sep 21, 2009 at 10:05 AM, phoebebright 
> <phoebebri...@spamcop.net>wrote:
>
>
>
> > Have been stuck on this one for a couple of days so hoping for some
> > enlightenment from some more able django users.  Am aware of the
> > 'gotcha' where the model name matches and attribute or one of the Meta
> > values.
>
> > I am getting this when a form is instantiated with an existing object
> > - no problem if the form is blank.
>
> Since you are getting an error when the form is instantiated with an
> existing object, that would have been more helpful code to post than the
> model definition.  It appears based on the error you are getting that in
> this case you are passing the existing object as the first positional
> argument?  At any rate the model instance you are using appears to be
> getting assigned to the form data attribute, which could happen if you are
> passing the instance as the first positional argument when you create the
> form.
>
> I do not think the problem has anything to do with the names of the fields
> in your model but rather it has to do with exactly what code you are using
> to create the form when you have an existing instance you want to use.
>
> Karen

Karen,

Spot on with the first positional argument I think, but I now get the
error:
form = TweetForm(instance=obj)
TypeError: __init__() got an unexpected keyword argument 'instance'


Here is the view:

    if request.method == 'POST':
        form = TweetForm(request.POST)
        etc.
    elif isinstance(obj, TweetLog):
        form = TweetForm(instance=obj)     <----- had TweetForm(obj)
before!
    else:
        default_taglist = request.session.get('taglist', '')
        form = TweetForm(initial = {'tweet_taglist' :
default_taglist}) # An unbound form

    return form

And the form:

class TweetForm(forms.Form):

    tweet = forms.CharField(widget=TweetFieldWidget(), required=True)
    tweet_taglist = forms.CharField(max_length=100, required=False)
    process_backwards = forms.BooleanField(required=False)

    attached_notes = forms.CharField(widget=forms.Textarea,
required=False)
    attached_url = forms.URLField(required=False)
    attached_file = forms.FileField(required=False)
    attached_image = forms.ImageField(required=False)

    class Media:
        js = ('/js/jquery.js', '/js/jquery-ui.min.js','js/
jeditable.js','js/tweetform.js', 'js/jquery-ui.tabs.js')
        css = { 'all': ('/css/jquery-ui.css','/css/smoothness/jquery-
ui-1.7.2.custom.css') }

    class Meta :
        model = TweetLog
        fields =
('tweet','attached_notes','attached_url','attached_file','attached_image')

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to