On Mon, Jun 16, 2008 at 6:49 PM, Richard Green <[EMAIL PROTECTED]>
wrote:

>
> Hi there - has anybody got a simple example of a newform that has a
> few fields that are not edited by the user - a simple example is a
> "comment" field -
> the table looks something like :
>
> class Comment(models.Model):
>    commentText = models.CharField(max_length=100)
>    commentUser = models.ForeignKey(User, editable=False)
>
> The form :
>
> class CommentForm(ModelForm):
>    class Meta:
>        model = Comment
>
> and in the view :
>
> @login_required
> def add_comment(request):
>    if request.method == 'POST':
>        form = CommentForm(request.POST)
>        if form.is_valid():
>            u = request.user
>            form.user = u
>            form.save()
>
> ( I won't bore you with the rest...)
>
> Pretty frickin simple right? For the life of me I can't get it to
> work ! Please don't just point me towards the docs at
> http://www.djangoproject.com/documentation/modelforms/ as they don't
> have any real concrete working examples I can work from - and the
> statement : "To avoid this failure, you must instantiate your model
> with initial values for the missing, but required fields, or use
> save(commit=False) and manually set any extra required fields:"  just
> does NOT work for me....
>
> A working 20 line example would suit me grandly !! Thanks in advance,
> Richard.


You seem to have gotten so frustrated that you neglected to mention what,
exactly, isn't working?  Is the form not showing what you want, are you
getting an error, etc?  More specifics on what is going wrong would probably
help someone help you.

Karen

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to