Beispiel #1
0
class Page(BasePage):
    descendants = Relationship(
        "self",
        Q(slug__startswith=L("slug"), slug__ne=L("slug")),
        related_name="ascendants",
    )

    subtree = Relationship(
        "self", Q(slug__startswith=L("slug")), related_name="rootpath"
    )

    def __str__(self):
        return self.name
 def __init__(self, **kwargs):
     kwargs.setdefault("related_name", "rootpath")
     kwargs.update({
         "to": "self",
         "predicate": Q(path__startswith=L("path")),
     })
     super(MP_Subtree, self).__init__(**kwargs)
Beispiel #3
0
class Category(models.Model):
    code = models.TextField(unique=True)
    members = Relationship(
        Categorised, Q(category_codes__contains=L("code")), related_name="categories"
    )

    def __str__(self):
        return "Category #%d: %s" % (self.pk, self.code)
 def __init__(self, **kwargs):
     kwargs.setdefault("related_name", "ascendants")
     kwargs.update({
         "to":
         "self",
         "predicate":
         Q(path__startswith=L("path"), path__ne=L("path")),
     })
     super(MP_Descendants, self).__init__(**kwargs)
Beispiel #5
0
class ProductFilter(models.Model):
    fcolour = models.CharField(max_length=20)
    fsize = models.IntegerField()

    products = Relationship(
        Product, Q(colour=L("fcolour"), size__gte=L("fsize")), related_name="filters"
    )

    cartitems = Relationship(
        CartItem,
        Q(product__colour=L("fcolour"), product__size__gte=L("fsize")),
        related_name="filters",
    )

    blah = Relationship

    def __str__(self):
        return "ProductFilter #%d: %s size %s" % (self.pk, self.fcolour, self.fsize)
Beispiel #6
0
class CartItem(models.Model):
    product_code = models.CharField(max_length=13)
    description = models.TextField()

    product = Relationship(
        Product, Q(sku=L("product_code")), related_name="cart_items", multiple=False
    )

    def __str__(self):
        return "Cart item #%s: SKU %s" % (self.pk, self.sku)
Beispiel #7
0
 def resolve_expression(self,
                        query=None,
                        allow_joins=True,
                        reuse=None,
                        summarize=False,
                        for_save=False):
     translate_lookups = query.model._tree_manager._translate_lookups
     translated_filters = translate_lookups(**self.filters)
     clone_q = Q(**translated_filters)
     # We must promote any new joins to left outer joins so that when Q is
     # used as an expression, rows aren't filtered due to joins.
     return clone_q.resolve_expression(query, allow_joins, reuse, summarize,
                                       for_save)
 def __init__(self, **kwargs):
     kwargs.setdefault("related_name", "rootpath")
     kwargs.update({
         "to":
         "self",
         "predicate":
         Q(
             tree_id=L("tree_id"),
             lft__gte=L("lft"),
             lft__lt=L("rgt"),
         ),
     })
     super(NS_Subtree, self).__init__(**kwargs)
 def __init__(self, **kwargs):
     kwargs.setdefault("related_name", "ascendants")
     kwargs.update({
         "to":
         "self",
         "predicate":
         Q(
             tree_id=L("tree_id"),
             lft__gt=L("lft"),
             lft__lt=L("rgt"),
         ),
     })
     super(NS_Descendants, self).__init__(**kwargs)
Beispiel #10
0
class SavedFilter(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    search_regex = models.TextField()
    chemicals = Relationship(Chemical, Q(formula__regex=L("search_regex")))