Edit form not being instanciated
        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:13 UTC
        
        
        Read the original article
        Hit count: 193
        
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