Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango "Enter a list of values" form error when rendering a ManyToManyField as a Textarea
    primarykey
    data
    text
    <p>I'm trying to learn Django and I've ran into some confusing points. I'm currently having trouble creating a movie using a form. The idea of the form is to give the user any field he'd like to fill out. Any field that the user fills out will be updated in its respective sql table (empty fields will be ignored). But, the form keeps giving me the error "Enter a list of values" when I submit the form. To address this, I thought stuffing the data from the form into a list and then returning that list would solve this.</p> <p>The first idea was to override the <code>clean()</code> in my ModelForm. However, because the form fails the <code>is_valid()</code> check in my views, the <code>cleaned_data</code> variable in <code>clean()</code> doesn't contain anything. Next, I tried to override the <code>to_python()</code>. However, <code>to_python()</code> doesn't seem to be called. </p> <p>If I put <code>__metaclass__ = models.SubfieldBase</code> in the respective model, I receive the runtime error </p> <blockquote> <p>"TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases"</p> </blockquote> <p>My approach doesn't seem to work. I'm not sure how to get around the 'Enter a list of values" error! Any advice?</p> <p>Here is the relevant code (updated):</p> <pre><code>models.py """ Idea: A movie consists of many equipments, actors, and lighting techniques. It also has a rank for the particular movie, as well as a title. A Theater consists of many movies. A nation consists of many theaters. """ from django.db import models from django.contrib.auth.models import User class EquipmentModel(models.Model): equip = models.CharField(max_length=20) # user = models.ForeignKey(User) class ActorModel(models.Model): actor = models.CharField(max_length=20) # user = models.ForeignKey(User) class LightModel(models.Model): light = models.CharField(max_length=20) # user = models.ForeignKey(User) class MovieModel(models.Model): # __metaclass__ = models.SubfieldBase rank = models.DecimalField(max_digits=5000, decimal_places=3) title = models.CharField(max_length=20) equipments = models.ManyToManyField(EquipmentModel, blank=True, null=True) actors = models.ManyToManyField(ActorModel, blank=True, null=True) lights = models.ManyToManyField(LightModel, blank=True, null=True) class TheaterModel(models.Model): movies = models.ForeignKey(MovieModel) class NationModel(models.Model): theaters = models.ForeignKey(TheaterModel) ===================================== forms.py """ These Modelforms tie in the models from models.py Users will be able to write to any of the fields in MovieModel when creating a movie. Users may leave any field blank (empty fields should be ignored, ie: no updates to database). """ from django import forms from models import MovieModel from django.forms.widgets import Textarea class MovieModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(MovieModelForm, self).__init__(*args, **kwargs) self.fields["actors"].widget = Textarea() self.fields["equipments"].widget = Textarea() self.fields["lights"].widget = Textarea() def clean_actors(self): data = self.cleaned_data.get('actors') print 'cleaning actors' return [data] class Meta: model = MovieModel ============================================= views.py """ This will display the form used to create a MovieModel """ from django.shortcuts import render_to_response from django.template import RequestContext from forms import MovieModelForm def add_movie(request): if request.method == "POST": form = MovieModelForm(request.POST) if form.is_valid(): new_moviemodel = form.save() return HttpResponseRedirect('/data/') else: form = MovieModelForm() return render_to_response('add_movie_form.html', {form:form,}, context_instance=RequestContext(request)) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload