我的模型中有以下两个类:
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不被识别。你可以帮帮我吗 ?
在 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) CardActionArea当我点击它时,我有一个重定向到另一个页面:
<Card>
<CardContent>
<CardActionArea component={RouterLink} to={`/poll/${poll.id}`} >
// My code
</CardActionArea>
</CardContent>
</Card>
Run Code Online (Sandbox Code Playgroud)
我把Button在CardActionArea中,当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()而不被重定向。
谁来帮帮我 ?
我想知道为什么以下这些代码不相等:
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)
对于第一个代码,我得到以下错误:
未设置对象变量或带块变量
有人可以帮我吗?