Products catalogue: filter by parameters

I need to make the filter products by features. So, products model: class Product(models.Model): name = models.CharField(max_length=255, unique=True') And feature models: class Value(models.Model): value = models.CharField(max_length=50) class FeatureName(models.Model): name = models.CharField(max_length=50) class Feature(models.Model): name = models.ForeignKey(FeatureN

产品目录:按参数过滤

我需要按功能制作过滤器产品。 所以,产品型号: class Product(models.Model): name = models.CharField(max_length=255, unique=True') 和特征模型: class Value(models.Model): value = models.CharField(max_length=50) class FeatureName(models.Model): name = models.CharField(max_length=50) class Feature(models.Model): name = models.ForeignKey(FeatureName) value = models.Forei

django

Im trying to do a formset with the following models (boost is the primary): class boost(models.Model): creator = models.ForeignKey(userInfo) game = models.ForeignKey(gameInfo) name = models.CharField(max_length=200) desc = models.CharField(max_length=500) rules = models.CharField(max_length=500) subscribe = models.IntegerField(default=0) class userInfo(models.Model): pi

Django的

我试图用下列模型做一个formset(boost是主要的): class boost(models.Model): creator = models.ForeignKey(userInfo) game = models.ForeignKey(gameInfo) name = models.CharField(max_length=200) desc = models.CharField(max_length=500) rules = models.CharField(max_length=500) subscribe = models.IntegerField(default=0) class userInfo(models.Model): pic_url= models.URLField(defa

django queryset filter datetimefield

I am strungling to use the django queryset API reference with filters based on the DateTimeField. I have prepared the following model, in my models.py: class KleedkamerIndeling(models.Model): gametimedate = models.DateTimeField(auto_now=False, auto_now_add=False) # date and time of game hometeam = models.CharField(max_length=25, blank=True) # name of home playing team

django queryset过滤器datetimefield

我在使用基于DateTimeField的过滤器来使用django queryset API参考。 我在我的models.py中准备了以下模型: class KleedkamerIndeling(models.Model): gametimedate = models.DateTimeField(auto_now=False, auto_now_add=False) # date and time of game hometeam = models.CharField(max_length=25, blank=True) # name of home playing team team homedressroom = models.CharField(max_length=25

Creating many objects using django

I'm using django-polymorphic and have a base class with about 8 derived classes. It works great except when I try to create many objects at once, in this case the performance is very poor. My code looks like this: class Parent(PolymorphicModel): ... class DerivedA(Parent): ... class DerivedB(Parent): ... @transaction.commit_on_success def create_objects() for model_class in (Deriv

使用django创建许多对象

我使用的是django-polymorphic,并有一个包含大约8个派生类的基类。 除了当我尝试一次创建多个对象时,它的效果很好,在这种情况下,性能非常差。 我的代码如下所示: class Parent(PolymorphicModel): ... class DerivedA(Parent): ... class DerivedB(Parent): ... @transaction.commit_on_success def create_objects() for model_class in (DerivedA, DerivedB...): instance = model_class(...) instanc

How do I query on two incoming models using the Django ORM?

I've got the following models: class DataStream(models.Model): category = models.CharField(max_length=255) description = models.TextField() class DataStreamSubCategory(models.Model): data_stream = models.ForeignKey(DataStream) sub_category = models.CharField(max_length=255) class DataStreamExample(models.Model): data_stream = models.ForeignKey(DataStream) example =

如何使用Django ORM在两个传入模型上查询?

我有以下型号: class DataStream(models.Model): category = models.CharField(max_length=255) description = models.TextField() class DataStreamSubCategory(models.Model): data_stream = models.ForeignKey(DataStream) sub_category = models.CharField(max_length=255) class DataStreamExample(models.Model): data_stream = models.ForeignKey(DataStream) example = models.CharField(max

differentiate null=True, blank=True in django

When we add a database field in django we generally write models.CharField(max_length=100, null=True, blank=True) . The same is done with ForeignKey , DecimalField etc. What is the basic difference in having null=True only blank=True only null=True , blank=True in respect to different ( CharField , ForeignKey , ManyToManyField , DateTimeField ) fields. What are the advantages/disadvanta

在django中区分null = True,blank = True

当我们在django中添加数据库字段时,我们通常会编写models.CharField(max_length=100, null=True, blank=True) 。 对于ForeignKey , DecimalField等也是这样做的。具有什么基本差异 null=True仅为null=True blank=True仅为blank=True null=True , blank=True 关于不同的( CharField , ForeignKey , ManyToManyField , DateTimeField )字段。 使用1/2/3有什么优点/缺点? null=True在数据库中的列上设置NULL

What is a "slug" in Django?

When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? (I have read its definition in this glossary.) It's a way of generating a valid URL, generally using data already obtained. For instance, using the title of an article to g

Django中的“slug”是什么?

当我读取Django代码时,我经常在模型中看到所谓的“slu”“。 我不太确定这是什么,但我知道它与URL有关。 如何以及何时应该使用这个slu thing的东西? (我已阅读本术语表中的定义。) 这是一种生成有效URL的方式,通常使用已获得的数据。 例如,使用文章的标题来生成一个URL。 我建议使用一个函数,给出一个标题(或其他数据),而不是手动设置它来生成slu generate。 一个例子: <title> The 46 Year Old Virgin

Django filter JSONField list of dicts

I run Django 1.9 with the new JSONField and have the following Test model : class Test(TimeStampedModel): actions = JSONField() Let's say the action JSONField looks like this : [ { "fixed_key_1": "foo1", "fixed_key_2": { "random_key_1": "bar1", "random_key_2": "bar2", } }, { "fixed_key_1": "foo2", "fixed_key_2": { "random_key_3": "bar2",

Django过滤器JSONField字典列表

我使用新的JSONField运行Django 1.9并具有以下测试模型: class Test(TimeStampedModel): actions = JSONField() 假设JSONField的动作如下所示: [ { "fixed_key_1": "foo1", "fixed_key_2": { "random_key_1": "bar1", "random_key_2": "bar2", } }, { "fixed_key_1": "foo2", "fixed_key_2": { "random_key_3": "bar2", "random_key_4": "bar3", } } ] 我希

How do I filter ForeignKey choices in a Django ModelForm?

Say I have the following in my models.py : class Company(models.Model): name = ... class Rate(models.Model): company = models.ForeignKey(Company) name = ... class Client(models.Model): name = ... company = models.ForeignKey(Company) base_rate = models.ForeignKey(Rate) Ie there are multiple Companies , each having a range of Rates and Clients . Each Client should have a base

如何在Django ModelForm中过滤ForeignKey选项?

假设我在models.py有以下内容: class Company(models.Model): name = ... class Rate(models.Model): company = models.ForeignKey(Company) name = ... class Client(models.Model): name = ... company = models.ForeignKey(Company) base_rate = models.ForeignKey(Rate) 即有多家Companies ,每家Companies都有一系列Rates和Clients 。 每位Client的基本Rate应从其母公司Company's Rates ,而非

Pipe character in Python

I see a "pipe" character ( | ) used in a function call: res = c1.create(go, come, swim, "", startTime, endTime, "OK", ax|bx) What is the meaning of the pipe in ax|bx ? It is a bitwise OR of integers. For example, if one or both of ax or bx are 1 , this evaluates to 1 , otherwise to 0 . It also works on other integers, for example 15 | 128 = 143 15 | 128 = 143 , ie 00001111 | 1000

Python中的管道字符

我在函数调用中看到一个“管道”字符( | ): res = c1.create(go, come, swim, "", startTime, endTime, "OK", ax|bx) ax|bx管道的含义是什么? 它是整数的按位或。 例如,如果ax或bx中的一个或两个都是1 ,则评估为1 ,否则评估为0 。 它也适用于其他整数,例如15 | 128 = 143 15 | 128 = 143 ,即00001111 | 10000000 = 10001111 00001111 | 10000000 = 10001111二进制。 这也是联合集合运算符set([1,2]) | set([2,3])