小编Hip*_*GER的帖子

Django:OneToOneField-RelatedObjectDoesNotExist

我的模型中有以下两个类:

class Answer(models.Model):
    answer = models.CharField(max_length=300)
    question = models.ForeignKey('Question', on_delete=models.CASCADE)

    def __str__(self):
        return "{0}, view: {1}".format(self.answer, self.answer_number)


class Vote(models.Model):
    answer = models.OneToOneField(Answer, related_name="votes", on_delete=models.CASCADE)
    users = models.ManyToManyField(User)

    def __str__(self):
        return str(self.answer.answer)[:30]
Run Code Online (Sandbox Code Playgroud)

在外壳中我采取第一个答案:

>>> Answer.objects.all()[0]
<Answer: choix 1 , view: 0>
Run Code Online (Sandbox Code Playgroud)

我想获得 Vote 对象:

>>> Answer.objects.all()[0].votes
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\Hippolyte\AppData\Roaming\Python\Python38\site-packages\django\db\models\fields\related_descriptors.py", line 420, in __get__
    raise self.RelatedObjectDoesNotExist(
questions.models.Answer.votes.RelatedObjectDoesNotExist: Answer has no votes.
Run Code Online (Sandbox Code Playgroud)

但发生了错误。

我不明白为什么related_name不被识别。你可以帮帮我吗 ?

python django one-to-one

7
推荐指数
1
解决办法
7380
查看次数

Material-UI:长文本包裹在网格中

在 Material-UI 的文档中,在Grid:white-space:nowrap;部分中 有一个包含在codesandbox中的文本示例。

在此示例中,我替换const message =""为不带空格的长文本:

const message ="AsuperLongTextWithNoSpaceItIsVeryAnnoyingIWantToWrapThisSentence"

结果:

在此输入图像描述

正如您所看到的,消息超出了网格。我希望消息能够换行。

我尝试style={{'overflowWrap': 'break-word'}}这样添加:

<Paper className={classes.paper}>
  <Grid container wrap="nowrap" spacing={2}>
    <Grid item>
      <Avatar>W</Avatar>
    </Grid>
    <Grid item xs>
      <Typography style={{'overflowWrap': 'break-word'}}>{message}</Typography> {/* style added */}
    </Grid>
  </Grid>
</Paper>
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

正如您所看到的,它更好了,但是文本也超出了网格。

如何在不越过网格的情况下正确地做到这一点?

编辑(1)

我有一个网格中的网格:

<Grid container spacing={2}>
    <Grid item>
        <Avatar>
            <ImageIcon />
        </Avatar>
    </Grid>
    <Grid item xs={12} sm container >
        <Grid item xs container direction="column" spacing={2} wrap="nowrap">
            <Grid item xs>
                <Typography gutterBottom variant="subtitle1">
                    {`${props.comment.username}`}
                </Typography> …
Run Code Online (Sandbox Code Playgroud)

grid reactjs material-ui

6
推荐指数
1
解决办法
2万
查看次数

Material-UI:CardActionArea 中的按钮

CardActionArea当我点击它时,我有一个重定向到另一个页面:

<Card>
    <CardContent>
        <CardActionArea component={RouterLink} to={`/poll/${poll.id}`} >
            // My code
        </CardActionArea>
    </CardContent>
</Card>
Run Code Online (Sandbox Code Playgroud)

我把ButtonCardActionArea中,当Button点击它的其他作用:

<Card>
    <CardContent>
        <CardActionArea component={RouterLink} to={`/poll/${poll.id}`} >
            <Button  onClick={props.myAction}>
                {answer.text}
            </Button>
        </CardActionArea>
    </CardContent>
</Card>
Run Code Online (Sandbox Code Playgroud)

我的问题是:

当我点击 时Button,我也点击了CardActionArea。我不想点击CardActionArea,而只是点击Button并调用 mymyAction()而不被重定向。

谁来帮帮我 ?

reactjs material-ui

2
推荐指数
1
解决办法
1113
查看次数

If-Then-Else-EndIf VERSUS IIF

我想知道为什么以下这些代码不相等:

test = IIf(CURRENCY_ Is Nothing, " ", IIf(IsEmpty(CURRENCY_.Value), " ", CStr(CURRENCY_.Value)))
Run Code Online (Sandbox Code Playgroud)

If CURRENCY_ Is Nothing Then
     test = " "
Else: IsEmpty (CURRENCY_.Value)
     test = CStr(CURRENCY_.Value)
End If
Run Code Online (Sandbox Code Playgroud)

对于第一个代码,我得到以下错误:

未设置对象变量或带块变量

有人可以帮我吗?

vba if-statement

1
推荐指数
1
解决办法
38
查看次数

标签 统计

material-ui ×2

reactjs ×2

django ×1

grid ×1

if-statement ×1

one-to-one ×1

python ×1

vba ×1