humanbeing
humanbeing

Reputation: 91

Django FileNotFoundError at /admin

I have model registered on admin page:

models.py

from django.db import models

class Question(models.Model):
    cat = models.IntegerField()
    quest = models.TextField(max_length=200)
    answer = models.CharField(max_length=1000)
    path = models.FilePathField()
    date = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(default=0)

    def __str__(self):
        return f'{self.cat} - {self.quest}'

admin.py

from django.contrib import admin
from .models import Question

admin.site.register(Question)

and I can see a database through admin page: https://i.sstatic.net/SuCcX.png

but I can't click on any record of the table and modify it due to an error: https://i.sstatic.net/M6W5a.png

I did it many times since now, and I have never encountered such an error. Does anybody have an idea how to fix it?

Upvotes: 1

Views: 1562

Answers (1)

Pawel
Pawel

Reputation: 441

Acorrding to Django docs FilePathField() has one required argument path, which is:

"The absolute filesystem path to a directory from which this FilePathField should get its choices."

So you need modify your models.py:

class Question(models.Model):
    ...
    path = models.FilePathField(path='/home/images')
    ...

Upvotes: 2

Related Questions