朋友们好,我不太熟悉将查询集合并为一个。如何在不改变模板设计的情况下达到我想要的结果?
注意:我已经问过这个问题了。我刚刚发现在 Django 中有组合多个查询集这样的事情。不过,这不是同一个问题。
这是我的views.py:
Markingbehaviors = StudentsBehaviorGrades.objects.filter(Teacher=teacher) \
.filter(Students_Enrollment_Records__in=Students.values_list('id')).values('Grading_Period').distinct('Grading_Period')\
.order_by('Grading_Period')
Marking = StudentsBehaviorGrades.objects.filter(Teacher=teacher) \
.filter(Students_Enrollment_Records__in=Students.values_list('id'))
cores = StudentsBehaviorGrades.objects.filter(Teacher=teacher) \
.filter(Students_Enrollment_Records__in=Students.values_list('id')).values(
'Marking__Marking',
'Grading_Behavior__Grading_Behavior__Name',
'Grading_Behavior__Grading_Behavior__GroupName').distinct(
'Grading_Behavior__Grading_Behavior__Name') \
.order_by('Grading_Behavior__Grading_Behavior__Name')
behaviors = StudentsBehaviorGrades.objects.filter(Teacher=teacher) \
.filter(Students_Enrollment_Records__in=Students.values_list('id')).values(
'Marking__Marking',
'Grading_Behavior__Grading_Behavior__Name',
'Grading_Behavior__Grading_Behavior__GroupName').distinct(
'Grading_Behavior__Grading_Behavior__GroupName') \
.order_by('Grading_Behavior__Grading_Behavior__GroupName')
matches = cores.union(Marking,behaviors)
Run Code Online (Sandbox Code Playgroud)
这是我的 html:
<tr>
{% for quarter in Markingbehaviors %}
td class="tdquarter">Q {{quarter.Grading_Period}}</td>
{% endfor %}
</tr>
{% for match in matches %}
<tr>
<td rowspan="2" colspan="4" class="tblcoretitle">{{match.Grading_Behavior__Grading_Behavior__Name}}</td>
</tr>
<tr>
<td colspan="4" class="tblcore">{{match.Grading_Behavior__Grading_Behavior__GroupName}}</td>
<td class="tblcore">{{match.Marking.Marking}}</td>
</tr>
{% endfor …Run Code Online (Sandbox Code Playgroud) 我只是开始用IntelliJ IDEA在Java中用一些简单的函数来编写Discord Bot。现在我确实有一个问题,我必须为特定功能使用语言级别8,但是当我这样做时,它给我一个错误,以前没有任何工作现在可以正常工作。
码:
package main;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.User;
import java.util.List;
import javax.security.auth.login.LoginException;
public class Main extends ListenerAdapter {
public static void main(String[] args) throws LoginException {
JDABuilder builder = new JDABuilder(AccountType.BOT);
String token = "Token of bot which i dont want to show here";
builder.setToken(token);
builder.addEventListener(new main.Main());
builder.buildAsync();
}
@Override
public void onMessageReceived(MessageReceivedEvent event) {
System.out.println("We received a message from " +
event.getAuthor().getName()+": "+ event.getMessage().getContentDisplay());
if(event.getMessage().getContentRaw().equals("!ping")) …Run Code Online (Sandbox Code Playgroud) 我正在使用JDA lib 创建我的不和谐机器人,但遇到了一个问题:为了使用文件发送消息,我应该使用现有消息:
RestAction<Message> sendFile(File file, Message message)
RestAction<Message> sendFile(File file, String fileName, Message message)
RestAction<Message> sendFile(InputStream data, String fileName, Message message)
Run Code Online (Sandbox Code Playgroud)
没有使用简单字符串消息发送文件的实现。因此,当我尝试发送文件并向其传递消息时,我收到了重复的消息。
所以问题是:如何Message在不重复消息的情况下创建附加文件?
我是 Java Discord API 的新手,我正在尝试在用户加入时运行函数。根据javadocs,您需要启用 GatewayIntent GUILD_MEMBERS,默认情况下禁用,但是当我使用 JDABuilder#enableIntents(GatewayIntent.GUILD_MEMBERS); 运行机器人时 我收到错误代码。
CloseCode(4014 / 不允许的意图。您的机器人可能没有资格请求特权意图,例如 GUILD_PRESENCES 或 GUILD_MEMBERS。)
我正在按照教程制作一个基本的 Discord Bot,(https://medium.com/discord-bots/making-a-basic-discord-bot-with-java-834949008c2b)我得到了错误,无法设置org.gradle.api.Project 类型的根项目“Blue Bot”的未知属性“mainClassName”,我不知道如何修复它。这是我的build.grade代码
plugins {
id 'java'
}
mainClassName = "Main"
group 'BlueBot'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'net.dv8tion:JDA:4.0.0_62'
}
Run Code Online (Sandbox Code Playgroud)
这是我的Main.java代码
import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import javax.security.auth.login.LoginException;
public class Main extends ListenerAdapter {
public static void main(String[] args) throws LoginException {
JDABuilder builder = new JDABuilder(AccountType.BOT);
String token = "enter token …Run Code Online (Sandbox Code Playgroud) 该CompletableFutureAPI 允许我们用来thenCompose链接另一个 future:
CompletableFuture<String> future1 = submit("foo");
CompletableFuture<String> future2 = future.thenCompose((result) -> submit(result));
Run Code Online (Sandbox Code Playgroud)
但这仅适用于成功的响应。有没有办法做同样的事情,但还包括异常处理?
例如:
CompletableFuture<String> future1 = submit("foo");
CompletableFuture<String> future2 = future.handleCompose((result, error) -> {
if (error != null)
return submit("failure"); // Handle error by doing a different action with the same result (like a fallback)
else
return submit(result);
});
Run Code Online (Sandbox Code Playgroud)
我知道你可以这样做whenComplete:
CompletableFuture<String> future2 = new CompletableFuture<>();
CompletableFuture<String> future1 = submit("foo");
future.whenComplete((result, error) -> {
CompletableFuture<String> tmp;
if (error != null)
tmp = submit("failure"); …Run Code Online (Sandbox Code Playgroud) 我目前正在使用discord4j 开发一个机器人,我想在其中添加反应(表情符号)到消息中。但我不知道如何使用 addReaction() 方法,并且我找到的每个示例都使用旧版本。在 dicord4j 的早期版本中,您可以将表情符号的 unicode 表示形式的字符串作为参数,但现在它只接受 ReactionEmoji 类型的对象。我查看了它的方法,除了 ReactionEmoji.unicode(String raw) 之外,没有什么真正有意义的,但随后我收到错误消息“未知表情符号”。作为字符串的输入,我尝试了 unicode,即实际的表情符号本身,然后进入调试模式,向消息添加反应,然后在调试模式下获取反应,并复制反应的原始值,将其粘贴为unicode() mehtod 的输入参数,但它仍然没有将其识别为表情符号。有一些我找不到的文档吗?我的代码:
Message msg = channel.createMessage("Test").block();
msg.addReaction("U+2B06").block();
Run Code Online (Sandbox Code Playgroud)