Sequelize查询以下SQL:(Sequelize query for the following SQL:)
我有一个SQL查询,我想写为Sequelize查询。
SELECT users.username, players.points, tournaments.date FROM USERS JOIN players ON users.id = players.UserId JOIN Tournaments ON tournaments.id = players.TournamentId WHERE players.player_checkedin_flag = 1 AND users.role = "user";
我在玩家表中有以下关联:
classMethods: { associate: function(models) { // Foreign key to user_id Player.belongsTo(models.User, { foreignKey: { allowNull: false } }); // Foreign key to tournament_id Player.belongsTo(models.Tournament, { foreignKey: { allowNull: false } });
在Users表中,
{ classMethods: { associate: function(models) { // User has many Player data User.hasMany(models.Player); } } }
在锦标赛表中:
{ classMethods: { associate: function(models) { // Tournament is connected to many player rows Tournament.hasMany(models.Player); } } }
对应的sequelize查询是什么?
I have a SQL query that I want to write as a Sequelize query.
SELECT users.username, players.points, tournaments.date FROM USERS JOIN players ON users.id = players.UserId JOIN Tournaments ON tournaments.id = players.TournamentId WHERE players.player_checkedin_flag = 1 AND users.role = "user";
I have the following association in Players table:
classMethods: { associate: function(models) { // Foreign key to user_id Player.belongsTo(models.User, { foreignKey: { allowNull: false } }); // Foreign key to tournament_id Player.belongsTo(models.Tournament, { foreignKey: { allowNull: false } });
In Users table,
{ classMethods: { associate: function(models) { // User has many Player data User.hasMany(models.Player); } } }
And in Tournaments table:
{ classMethods: { associate: function(models) { // Tournament is connected to many player rows Tournament.hasMany(models.Player); } } }
What is the corresponding sequelize query for it?
原文:https://stackoverflow.com/questions/43126729
最满意答案
您不必在单个语句中输出模板中的表单。 你可以这样做:
{% for field in user_form %} <p class="some-bootstrapclass">{{ field.label_tag }}{{ field }}</p> {% endfor %}
这是一个非常简化的例子。
不过我强烈建议你看看脆皮形式:
http://django-crispy-forms.readthedocs.org
使用crispy表单,您可以在forms.py中设置所有内容,并仍然在模板中的单个语句中输出表单,例如:
{% load crispy_forms_tags %} {% crispy user_form %}
You don't have to output the form in the template in a single statement. You could do something like:
{% for field in user_form %} <p class="some-bootstrapclass">{{ field.label_tag }}{{ field }}</p> {% endfor %}
This is very simplified example.
However I would strongly suggest you to take a look at crispy forms:
http://django-crispy-forms.readthedocs.org
With crispy forms you can set everything in your forms.py and still output the forms in a single statement in the template, for example:
{% load crispy_forms_tags %} {% crispy user_form %}
相关问答
更多-
在django注册(Registration in django)[2023-03-28]
django-registration是你应该在Django项目中寻找注册功能的第一个地方。 您可以使用用户配置文件存储有关用户的额外信息,并且可以为django-registration创建自己的自定义后端,以便在注册过程中提供自己的表单以收集和处理此额外信息。 请注意 ,您必须使用django-registration的开发版本(请参阅bitbucket页面 )以获得简单的自定义后端内容。 最后一点需要注意 - 这一切都假设您将使用Django contrib.auth.User模型,这是迄今为止推荐的 ... -
如何使用django-registration更改登录后页面?(How to change the post-login page using django-registration?)[2022-05-28]
LOGIN_REDIRECT_URL ='/' 这会重定向到主页。 LOGIN_REDIRECT_URL = '/' This redirects to home url. -
你可以将css放入static文件夹并在html中调用css : You can put the css into the static folder and call the css in the html: ...
-
如果你的行为是空白或. 然后该帖子转到呈现该表单的视图(URL)。 这是一个使用联系表单的简单示例; https://hellowebapp.com/news/tutorial-setting-up-a-contact-form-with-django/ If your action is blank or . then the post goes to the view (URL) which rendered the form. Here's a simple example using a conta ...
-
使用Django 1.6和Python 3.3.4进行django-registration 1.0(django-registration 1.0 with Django 1.6 and Python 3.3.4)[2023-12-24]
django-registration不支持Python 3.使用django-allauth代替。 你可以在这里找到关于django-allauth的更多信息: https ://pypi.python.org/pypi/django-allauth 希望这可以帮助。 django-registration doesn't support Python 3. Use django-allauth instead. You can find much about django-allauth here: h ... -
django-registration实际上很容易上手,虽然取决于你正在看哪些文档,它看起来有点压倒性。 你在看快速入门指南吗? 您真正需要做的就是安装它,为您的设置和urls.py各添加一行,并制作一些模板。 我认为可能有更好的示例模板,但这里是我的旧项目的模板。 该项目使用了在原始注册表单中放置配置文件信息的方法,这意味着制作一个简单的RegistrationForm子类 ,进行小型注册后端 ,并将其黑客入注册注册网址 。 (现在可能有更好的方法来做到这一点;我最初在4年前写过这篇文章并且在2年内没有触 ...
-
您不必在单个语句中输出模板中的表单。 你可以这样做: {% for field in user_form %}
{{ field.label_tag }}{{ field }}
{% endfor %} 这是一个非常简化的例子。 不过我强烈建议你看看脆皮形式: http://django-crispy-forms.readthedocs.org 使用crispy表单,您可以在forms.py中设置所有内容,并仍然在模板中的单个语 ... -
只需在registration-html-template中对您的登录表单进行硬编码即可。 它应该像魅力一样工作。 Just hard-code your login-form in the registration-html-template. It should work like a charm.
-
你必须使用: (r'^admin/', include(admin.site.urls)) 请参阅文档 。 You have to use: (r'^admin/', include(admin.site.urls)) See the documentation.
-
你忘了添加 EMAIL_HOST = 'smtp.mysite.com' 发送电子邮件。 You forget to add EMAIL_HOST = 'smtp.mysite.com' to send email.