Saya baru-baru ini mulai membuat aplikasi web Django untuk proyek pribadi saya. Saya telah membuat model, dan makemigrations / migrate berfungsi dengan baik. Ketika saya membuat formulir, dan menjalankan perintah itu, saya menerima kesalahan berikut: django.core.exceptions.FieldError: Unknown field(s) (mideals) specified for Sheet.

Form.py

from django import forms
from . import models

class CreateSheet(forms.ModelForm):
    class Meta:
        model = models.Sheet
        fields = [
            'name', 'slug', 'Class', 'background', 'race', 'xp', 'level',
            'strength', 'dexterity', 'constitution', 'intelligence', 'wisdom',
            'charisma', 'strengthMod', 'dexterityMod', 'constitutionMod',
            'intelligenceMod', 'wisdomMod', 'charismaMod', 'sStrength',
            'sDexterity', 'sConstitution', 'sIntelligence', 'sWisdom',
            'sCharisma', 'acrobatics', 'animalHandling', 'arcana', 'athletics',
            'deception', 'history', 'insight', 'intimidation', 'investigation',
            'medicine', 'nature', 'perception', 'performance', 'persuasion',
            'religion', 'sleightOfHand', 'stealth', 'survival',
            'acrobaticsMod', 'animalHandlingMod', 'arcanaMod', 'deceptionMod',
            'historyMod', 'insightMod', 'intimidationMod', 'investigationMod',
            'medicineMod', 'natureMod', 'perceptionMod', 'performanceMod',
            'persuasionMod', 'religionMod', 'sleightOfHandMod', 'stealthMod',
            'survivalMod', 'otherProficiencies', 'languages', 'equipment',
            'copper', 'silver', 'gold', 'platinum', 'armorClass', 'initiative',
            'speed', 'maxHitPoints', 'hitPoints', 'hitDice', 'sDeathSave1',
            'sDeathSave2', 'sDeathSave3', 'fDeathSave1', 'fDeathSave2',
            'fDeathSave3', 'personalityTraits', 'mideals', 'bonds', 'flaws',
            'featuresTraits',
        ]

Model.py

from django.db import models

# Create your models here.
class Sheet(models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField(default="")

    Class = models.CharField(max_length=100)
    background = models.CharField(max_length=100)
    race = models.CharField(max_length=100)
    xp = models.IntegerField()
    level = models.IntegerField()

    strength = models.IntegerField()
    dexterity = models.IntegerField()
    constitution = models.IntegerField()
    intelligence = models.IntegerField()
    wisdom = models.IntegerField()
    charisma = models.IntegerField()

    strengthMod = models.IntegerField()
    dexterityMod = models.IntegerField()
    constitutionMod = models.IntegerField()
    intelligenceMod = models.IntegerField()
    wisdomMod = models.IntegerField()
    charismaMod = models.IntegerField()

    sStrength = models.BooleanField()
    sDexterity = models.BooleanField()
    sConstitution = models.BooleanField()
    sIntelligence = models.BooleanField()
    sWisdom = models.BooleanField()
    sCharisma = models.BooleanField()

    acrobatics = models.BooleanField()
    animalHandling = models.BooleanField()
    arcana = models.BooleanField()
    athletics = models.BooleanField()
    deception = models.BooleanField()
    history = models.BooleanField()
    insight = models.BooleanField()
    intimidation = models.BooleanField()
    investigation = models.BooleanField()
    medicine = models.BooleanField()
    nature = models.BooleanField()
    perception = models.BooleanField()
    performance = models.BooleanField()
    persuasion = models.BooleanField()
    religion = models.BooleanField()
    sleightOfHand = models.BooleanField()
    stealth = models.BooleanField()
    survival = models.BooleanField()

    acrobaticsMod = models.IntegerField()
    animalHandlingMod = models.IntegerField()
    arcanaMod = models.IntegerField()
    deceptionMod = models.IntegerField()
    historyMod = models.IntegerField()
    insightMod = models.IntegerField()
    intimidationMod = models.IntegerField()
    investigationMod = models.IntegerField()
    medicineMod = models.IntegerField()
    natureMod = models.IntegerField()
    perceptionMod = models.IntegerField()
    performanceMod = models.IntegerField()
    persuasionMod = models.IntegerField()
    religionMod = models.IntegerField()
    sleightOfHandMod = models.IntegerField()
    stealthMod = models.IntegerField()
    survivalMod = models.IntegerField()

    otherProficiencies = models.CharField(max_length=250)
    languages = models.CharField(max_length=250)
    equipment = models.CharField(max_length=250)
    copper = models.IntegerField()
    silver = models.IntegerField()
    gold = models.IntegerField()
    platinum = models.IntegerField()

    armorClass = models.IntegerField()
    initiative = models.IntegerField()
    speed = models.IntegerField()
    maxHitPoints = models.IntegerField()
    hitPoints = models.IntegerField()
    hitDice = models.CharField(max_length=250)
    sDeathSave1 = models.BooleanField(default=False)
    sDeathSave2 = models.BooleanField(default=False)
    sDeathSave3 = models.BooleanField(default=False)
    fDeathSave1 = models.BooleanField(default=False)
    fDeathSave2 = models.BooleanField(default=False)
    fDeathSave3 = models.BooleanField(default=False)

    personalityTraits = models.CharField(max_length=250)
    ideals = models.CharField(max_length=250)
    bonds = models.CharField(max_length=250)
    flaws = models.CharField(max_length=250)
    featuresTraits = models.CharField(max_length=250)

    def __str__(self):
        return self.name

Aku benar-benar tidak tahu apa yang terjadi di sini. Saya telah melihat stack overflow dan sepertinya hampir tidak ada yang terkait dengan kesalahan saya. Bantuan apa pun akan sangat dihargai.

0
Hedgy 21 September 2019, 19:15

1 menjawab

Jawaban Terbaik

Anda menentukan bahwa Anda ingin bidang mideals disertakan dalam formulir, tetapi bidang itu tidak ada pada model Sheet. Anda harus menghapus bidang itu dari daftar bidang pada formulir atau menambahkannya ke model.

Jika Anda ingin semua bidang dari model muncul di formulir, akan lebih baik menggunakan fields = '__all__'

0
Mikey Lockwood 21 September 2019, 16:20