Django,一页上有两个表格,一个表格使用来自oth的数据

2024-10-01 00:28:43 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我的模型:

from django.db import models

ATTACK_TYPES = ('EXA','Example')

class AttackImage(models.Model):
    title = models.CharField(max_length=255)
    image = models.ImageField(upload_to='attack_images')
    source_url = models.URLField(blank=True,null=True)


class AttackItem(models.Model):
    attack_image = models.ForeignKey(AttackImage, on_delete=models.CASCADE)
    attack_used = models.CharField(max_length=55, choices=ATTACK_TYPES)
    hidden_data_found = models.BooleanField(blank=True)

我希望用户能够同时创建attackitem和attackimage,attackitem与attackimage具有foreignkey关系,如您所见。我该怎么做?提前谢谢。你知道吗


Tags: imagetruemodelmodelslengthmaxclasstypes