i have database of exhibition listings related foreign key database of venues take place. django templates access venue information in query results through listing.venue.name
, listing.venue.url
, , on.
however, exhibitions take place in temporary venues, , information stored in same database, in listing.temp_venue_url
, such. because seems wasteful , sad put conditionals on templates, want move info temporary venues templates expecting info regular venues. didn't work:
def transfer_temp_values(listings): listing in listings: if listing.temp_venue: listing.venue = venue listing.venue.name = listing.temp_venue listing.venue.url = listing.temp_venue_url listing.venue.state = listing.temp_venue_state listing.venue.location = listing.temp_venue_location
the error surprised me:
valueerror @ /[...]/ cannot assign "<class 'myproject.gsa.models.venue'>": "exhibition.venue" must "venue" instance.
i rather thought was. how go accomplishing this?
the error message because have assigned class venue
listing, rather instance of it. need call class instance:
listing.venue = venue()
Comments
Post a Comment