我有以下的Django模型。
class A(models.Model):
tmp = models.ForeignKey(B)
active = models.BooleanField()
class B(models.Model):
active = models.BooleanField()
archived = models.BooleanField()
现在,我有以下查询。
A.objects.select_related(B).filter(active=True)
现在,这将获取B的所有对象。现在,我如何在模型B的select_related子句
我正在尝试按字母顺序对翻译后的字段名称进行排序。我如何修改下面的代码来实现这一点呢?目前,此代码转换详细名称。现在,我想知道如何按字母顺序对翻译后的字段名进行排序。该网站将提供多种语言版本。
models.py
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
class User_interest(models.Model):
user = models.OneToOneField(User)
acting = models.
我是Django的初学者。我已经为我的Django项目创建了登录、注销和注册页面。当用户登录时,我希望他们只登录到他们所做的帖子。我不确定如何使用户,我已经能够登录到他们自己的页面,并管理他们的预算等。 Image of code from django.db import models
from django.contrib.auth.models import User# user authentication
from django.contrib.auth import get_user_model#for connecting the inbuild user database
在我的模型中,每个产品都有变体,每个变体都有orderitem。每个orderitem都有整数值,即数量。
在Django模板中有没有一种方法可以添加特定产品的所有数量并显示它?
class Product(models.Model):
name = models.CharField(max_length=255)
price = models.DecimalField(decimal_places=2, max_digits=12)
store = models.ForeignKey(Store)
class Variation(models.Model):
我试图在这样的Django模型中存储一个列表:
class Search(models.Model):
result = models.CharField(max_length=100,
null=True, blank=True)
name = models.BooleanField(default=True)
eotp = models.BooleanField(default=True)
reference = models.BooleanField(default=True)
date
我指的是下面列出的问题中的答案,因为我试图运行一个查询,该查询获取与django应用程序中给定点最近的对象。我的django版本是1.9.2。
在我看来,我正在传递一个邮政编码,并使用GeoPy获取位置和lat/long。
from django.contrib.gis.geos import *
from django.contrib.gis.measure import D
from geopy.geocoders import Nominatim
geolocator = Nominatim()
zipcode = self.request.query_params.get(
我想在用户模型上实现django信号,以创建用户配置文件。我想要创建用户配置文件时,任何用户将被注册。下面是我通过信号创建用户配置文件的代码:
from django.contrib.auth.models import User
@receiver(post_save, sender=User)
def user_is_created_or_save(sender,instance,created,**kwargs):
user = instance.user
first_name = instance.first_name
last
我是Django的新手,所以我只是做了一个项目来了解它,但我对这段代码有一点问题,我希望能够作为汽车obj,如果它是可用的,所以我做了一个:
>>>cars = Car.objects.all()
>>>print cars[0].category
>>>'A'
>>>cars[0].available(fr, to)
这会导致一个:
>>>global name 'category' is not defined
所以看起来我不能在类中访问self.category,你有
我正在尝试使用django-过滤器与django-rest框架来实现基于get/url/params的过滤器,但是它不适用于视图集,并且没有显示错误。例如,如果我使用一个generics.ListAPIView,过滤器就可以完美地工作!我的项目代码:
Models.py
class OrderFeedBack(BaseModel):
"""
Receive the customer rating, vendor and staff feedback about a order.
Once the vendor or the customer h
在Django,我有两个模型:
class A(models.Model):
# lots of fields
class B(models.Model):
a = models.ForeignKey(A)
member = models.BooleanField()
我需要构造一个查询,它过滤B并选择所有A,如下所示:
result = B.objects.filter(member=True).a
上面的示例代码当然会返回一个错误QuerySet has no attribute 'a'。
预期结果:只包含一个对象的QuerySet
实现所需功能的
我正在开发一个休假管理系统,在这个系统中,几个用户向一个特定的经理报告( django中的admin,假设有多个admin)。
from django.db import models
from django.contrib.auth.models import User
CHOICES = (('1','Earned Leave'),('2','Casual Leave'),('3','Sick Leave'),('4','Paid Leave'))
class
我需要了解如何在API中显示或隐藏由django rest框架序列化的对象。
我在我的管理模型中设置了一个复选框来设置活动或非活动对象(true或false)。
class Video(models.Model):
...
status = models.BooleanField('Activate video', default=False, help_text='If is checked show the video in the API')
...
在我的urls.py设置
from video.models import Vid
我在django模型中有一个字段:
class Norf(Models.model):
foo = models.BooleanField(default=False)
bar = models.BooleanField(default=False)
编写以下函数的最佳方法是什么?
def get_bool(self, n):
if n == 1:
return foo
if n == 2:
return bar
我正在为我的公司做一个流程。为此,我发现有必要存储插入到进程中的数据。我的流程运行良好,但它没有保存在其他模型中,而是继续将数据保存在对应于进程的表上,而不是保存在其他模型上。
models.py:
from __future__ import unicode_literals
from datetime import datetime
from django.db import models
from viewflow.models import Process
from django.contrib.auth.models import User
class DeliveryProce