Hi,
On 08.04.2009, at 16:43, ramya wrote:
>
> class Property(models.Model):
> property_id = models.AutoField(primary_key = True)
> property_name = models.CharField("Name", max_length = 30)
> user = models.ForeignKey(User)
>
> class PropertyForm(ModelForm):
> class Meta:
> model = Property
> exclude = ('user')
>
> def addProperty(request):
> formContent = PropertyForm(request.POST)
> formContent.save(commit = False)
> formContent.user = request.user
AFAIK, you can't assign values to a form field you properties.
> formContent.save()
>
try.
# create the new Property model instance, but don't save it to the DB.
new_property = formContent.save(commit=False)
# assign the user.
new_property.user = request.user
#save the model instance to the DB.
new_property.save()
adi
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---