Edit form not being instantiated

Posted by 47 on Stack Overflow See other posts from Stack Overflow or by 47
Published on 2010-03-27T18:09:38Z Indexed on 2010/03/27 18:23 UTC
Read the original article Hit count: 386

Filed under:
|

I have two models like this:

class OptionsAndFeatures(models.Model):
   options = models.TextField(blank=True, null=True)
   entertainment = models.TextField(blank=True, null=True)
   seats_trim = models.TextField(blank=True, null=True)
   convenience = models.TextField(blank=True, null=True)
   body_exterior = models.TextField(blank=True, null=True)
   lighting = models.TextField(blank=True, null=True)
   safety = models.TextField(blank=True, null=True)
   powertrain = models.TextField(blank=True, null=True)
   suspension_handling = models.TextField(blank=True, null=True)
   specs_dimensions = models.TextField(blank=True, null=True)
   offroad_capability = models.TextField(blank=True, null=True)
class Vehicle(models.Model):
   ...
   options_and_features = models.ForeignKey(OptionsAndFeatures, blank=True, null=True)

I have a model form for the OptionsAndFeaturesclass that I'm using in both the add and edit views. In the add view it works just fine. But the edit view renders the OptionsAndFeatures as blank. The code for the edit view is as follows:

def edit_vehicle(request, stock_number=None):   
   vehicle = get_object_or_404(Vehicle, stock_number=stock_number)

   if request.method == 'POST':
      # save info
   else:
       vehicle_form = VehicleForm(instance=vehicle)
       photos = PhotosFormSet(instance=vehicle)
       options = OptionsForm(instance=vehicle)

   #render_to_reponse

What could be the problem here?

© Stack Overflow or respective owner

Related posts about django

Related posts about forms