Вопрос

I'm getting a "DoesNotExist" error with the following set up - I've been trying to debug for a while and just can't figure it out.

class Video(models.Model):
    name = models.CharField(max_length=100)
    type = models.CharField(max_length=100)
    owner =  models.ForeignKey(User, related_name='videos')
    ...
    #Related m2m fields
    ....

class VideoForm(modelForm):
    class Meta:
        model = Video
        fields = ('name', 'type')

class VideoCreate(CreateView):
    template_name = 'video_form.html'
    form_class = VideoForm
    model = Video

When I do this and post data for 'name' and 'type' - I get a "DoesNotExist" error. It seems to work fine with an UpdateView - or when an 'instance' is passed to init the form.

This is the exact location where the error is raised: /usr/lib/pymodules/python2.7/django/db/models/fields/related.py in get, line 301

Does anyone know what might be going on?

Thanks

Это было полезно?

Решение

Since you have not posted your full traceback, my guess is that your owner FK is not optional, and you are not specifying one in your model form.

You need to post a full traceback.

Другие советы

I think it has to be class VideoForm(ModelForm) instead of VideoForm(modelForm).

If you aren't going to use the foreign key in the form use exclude = ('owner')

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top