当创建与表相关的视图时,Django或POSTGRESQL是否丢失了有关主键和外键的信息?
我有一个View-A (所有3个字段都是Foreign ),该视图从view获得2个字段。视图-B从表C中获取其字段。表-C有主键和外键.
因此,当我使用django模型访问View时,如何处理这些字段?我知道它们是外键,但是任何类型的过滤器都会导致一个空的Queryset。如果我用的是
myview = viewA.objects.using(db).all() # getting all the data
myview2= viewA.objects.using(db).all()[:5] # g
假设我有这些模型作为一个简单的例子:
class Event(models.Model):
name = models.CharField(max_length=50, default='')
app = models.ForeignKey(App)
class App(models.Model):
name = models.CharField(max_length=50, default='')
app_config = models.ForeignKey(AppConfig)
class AppConfig(models
我已经在我的GUI上创建了两个可可控件。NSButton和NSTextField。当用户点击按钮时,按钮处理程序将被执行。它将使按钮禁用并启用NSTextField。在结束编辑时,文本字段的字符串将显示为按钮标题。
button click
{
- Make button visible = false;
- Make text field visible = true;
- Text field allow selection = true;
- text field allow editing = true;
}
control text end editing
{
- te
有一个视频模型,我希望在SerializerMethodField上订购。需要进行排序的字段是“投票”和“喜欢”,对于这些字段,我使用了额外的django包,“票”和“django-hitcount”。
#models.py
class Video(models.Model, HitCountMixin):
'''
Other properties
'''
votes = VotableManager()
#serializer.py
class VideoListSerializer(ModelSerializ
我一直在谷歌上搜索,但我似乎不明白。
如何在django中重新创建简单的联接查询?
在models.py (Fylker是县,Dagensrepresentanter是人)
class Fylker(models.Model):
id = models.CharField(max_length=6, primary_key=True)
navn = models.CharField(max_length=300)
def __unicode__(self):
return self.navn
class Meta:
db_tabl
因此,我想执行一个查询,其中字段等于for循环中对象的属性。下面是一个使用sqlAlchemy的工作示例/示例:
you = session.query(Users).filter_by(id=login_session['userid']).first()
friends = session.query(Friends).filter_by(user_id=you.id).all()
dashboard = session.query(Markers).filter(Markers.owner.in_([f.friend_id for f in friends)]).
我有一个模型,其字段是日期和另一个模型文本字段的外键:
# models.py
class Publications(models.Model):
"""A class for daily article publications"""
date = models.DateField(
help_text="date for this article to be published"
)
headline = models.ForeignKey(
Articles,
我的Django项目有两个模型
class BookSerie(models.Model):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=255)
class BookVolume(models.Model):
isbn = models.CharField(max_length=17)
volumeNumber = models.PositiveIntegerField()
serie = models.ForeignKey(BookSerie
假设我有三个模特:
from django.db import models
class X(models.Model):
y = models.ForeignKey(Y, on_delete=models.PROTECT)
z = models.ForeignKey(Z, on_delete=models.PROTECT)
a = models.DecimalField(...)
b = models.DecimalField(...)
...some fields...
class Y(models.Model):
...some
我的models.py:
from django.db import models
from django.contrib.auth.models import User
class SkillCategory(models.Model):
title = models.CharField(max_length=255)
def __unicode__(self):
return self.title
class Meta:
verbose_name_plural = "Skill Categories"
cl
在我维护的django论坛中,我禁止虐待的用户使用4天。在论坛的“主页”中,我显示每个人的评论,但不包括被地狱禁止的人的评论。事情是这样的:
def get_queryset(self):
if self.request.user_banned: #if user is hell-banned
return Link.objects.order_by('-id')[:120]
else: #if user is not hell-banned
global condemned
我知道django不允许没有外键关系的连接,我也不能指定外键,因为一个表中的条目不在另一个表中(使用pyspark填充)。我需要一种有效的方法来查询以下内容:
假设我有以下表格:
公司|产品|用户总数|唯一用户总数
和
公司|产品|许可证数量|预计用户数
我想加入,这样我就可以在前台显示这样的表格
公司视图
产品|总用户数|唯一Users|#Licenses|#预估用户数
P1 | Num | Num
P2 | Num | Num
当前循环通过每个产品并执行查询(速度太慢且效率太低)来填充列表字典
效率太低了
我有三张桌子:
卡车和田里:id,name.
菜单和字段:id,itemname,id_foodtype,id_truck.
Foodtype和字段:id,type.
我想做个总结,比如:
id name total
10 Alcoholic drink 0
5 Appetizer 11
我的问题是用 elements返回结果。
我尝试了这样的SQL查询:
SELECT
ft.id, ft.name, COUNT(me.id) total
FROM
foodtype ft LEFT JOIN menu me
我正在使用一个查询集,其中包括一个ManyToMany字段brand_groups。用户只能根据其组织访问BrandGroups的子集。我试图在仍然使用与视图高度集成的ManyToMany时,将该字段过滤掉。
我正在使用的简化表:
class BrandGroup(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=256)
organization = models.ForeignKey(
Organization, r