Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » problem with multiple Foreignkeys in ModelForm [RSS Feed]

#1 Dec. 16, 2010 05:39:56

P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with multiple Foreignkeys in ModelForm


I'm getting the following error:
annot assign "<User: XXXX>": "Bid.bidder" must be a "Bidder" instance.

#classes
class Listing(models.Model):
owner = models.ForeignKey(User, verbose_name=_('Im the wanter'))
title = models.CharField(_('short description'), max_length=255)

class Bidder(models.Model):
user = models.ForeignKey(User, verbose_name=_('bidder'),
unique=True)

class Bid(models.Model):
listing = models.ForeignKey(Listing)
bidder = models.ForeignKey(Bidder)
bidding_price = models.DecimalField(_('offering bid',),
max_digits=6, decimal_places=2,blank=True, null=False)

#form
class BidForm(forms.ModelForm):
class Meta:
model = Bid
exclude = ('bidder', 'listing',)
#view
@login_required
def newbid(request,listing_id):
''' Create a new bid with request.user as owner
'''
if request.method == 'POST':
form = BidForm(request.POST)
if form.is_valid:
bid=form.save(commit=False)
bidder_person=Bidder(user = request.user)
bidder_person.save()

bid.bidder = bidder_person #problem is here!

l = get_object_or_404(Listing, pk=listing_id)
bid.listing = l
bid.listing.owner = l.owner
bid.save()
return HttpResponseRedirect(reverse('listings_all'))

else:
form = BidForm()

return create_object(
request,
form_class = BidForm
)

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » problem with multiple Foreignkeys in ModelForm [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support