本文整理汇总了Python中mezzanine.utils.models.base_concrete_model函数的典型用法代码示例。如果您正苦于以下问题:Python base_concrete_model函数的具体用法?Python base_concrete_model怎么用?Python base_concrete_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了base_concrete_model函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
def save(self, update_site=False, *args, **kwargs):
"""
Create a unique slug by appending an index. Set the site to
the current site when the record is first created, unless the
``update_site`` argument is explicitly set to ``True``.
"""
if not self.slug:
# For custom content types, use the ``Page`` instance for
# slug lookup.
concrete_model = base_concrete_model(Slugged, self)
self.slug = self.get_slug()
i = 0
while True:
if i > 0:
if i > 1:
self.slug = self.slug.rsplit("-", 1)[0]
self.slug = "%s-%s" % (self.slug, i)
qs = concrete_model.objects.all()
if self.id is not None:
qs = qs.exclude(id=self.id)
try:
qs.get(slug=self.slug)
except ObjectDoesNotExist:
break
i += 1
if update_site or not self.id:
self.site = Site.objects.get_current()
super(Slugged, self).save(*args, **kwargs)
示例2: set_content_model
def set_content_model(self):
"""
Set content_model to the child class's related name, or None if this is
the base class.
"""
is_base_class = (
base_concrete_model(ContentTyped, self) == self.__class__)
self.content_model = (
None if is_base_class else self.get_content_model_name())
示例3: save
def save(self, *args, **kwargs):
"""
Set the initial ordering value.
"""
if self._order is None:
lookup = self.with_respect_to()
concrete_model = base_concrete_model(Orderable, self)
self._order = concrete_model.objects.filter(**lookup).count()
super(Orderable, self).save(*args, **kwargs)
示例4: delete
def delete(self, *args, **kwargs):
"""
Update the ordering values for siblings.
"""
lookup = self.with_respect_to()
lookup["_order__gte"] = self._order
concrete_model = base_concrete_model(Orderable, self)
after = concrete_model.objects.filter(**lookup)
after.update(_order=models.F("_order") - 1)
super(Orderable, self).delete(*args, **kwargs)
示例5: generate_unique_slug
def generate_unique_slug(self):
"""
Create a unique slug by passing the result of get_slug() to
utils.urls.unique_slug, which appends an index if necessary.
"""
# For custom content types, use the ``Page`` instance for
# slug lookup.
concrete_model = base_concrete_model(Slugged, self)
slug_qs = concrete_model.objects.exclude(id=self.id)
return unique_slug(slug_qs, "slug", self.get_slug())
示例6: adjacent_by_order
def adjacent_by_order(self, direction):
"""
Retrieves next object by order in the given direction.
"""
lookup = self.with_respect_to()
lookup["_order"] = self._order + direction
concrete_model = base_concrete_model(Orderable, self)
try:
return concrete_model.objects.get(**lookup)
except concrete_model.DoesNotExist:
pass
示例7: save
def save(self, *args, **kwargs):
"""
Create a unique slug by appending an index.
"""
if not self.slug:
self.slug = self.get_slug()
# For custom content types, use the ``Page`` instance for
# slug lookup.
concrete_model = base_concrete_model(Slugged, self)
slug_qs = concrete_model.objects.exclude(id=self.id)
self.slug = unique_slug(slug_qs, "slug", self.slug)
super(Slugged, self).save(*args, **kwargs)
示例8: _get_next_or_previous_by_order
def _get_next_or_previous_by_order(self, is_next, **kwargs):
"""
Retrieves next or previous object by order. We implement our
own version instead of Django's so we can hook into the
published manager, concrete subclasses and our custom
``with_respect_to`` method.
"""
lookup = self.with_respect_to()
lookup["_order"] = self._order + (1 if is_next else -1)
concrete_model = base_concrete_model(Orderable, self)
try:
queryset = concrete_model.objects.published
except AttributeError:
queryset = concrete_model.objects.filter
try:
return queryset(**kwargs).get(**lookup)
except concrete_model.DoesNotExist:
pass
示例9: _get_next_or_previous_by_publish_date
def _get_next_or_previous_by_publish_date(self, is_next, **kwargs):
"""
Retrieves next or previous object by publish date. We implement
our own version instead of Django's so we can hook into the
published manager and concrete subclasses.
"""
arg = "publish_date__gt" if is_next else "publish_date__lt"
order = "publish_date" if is_next else "-publish_date"
lookup = {arg: self.publish_date}
concrete_model = base_concrete_model(Displayable, self)
try:
queryset = concrete_model.objects.published
except AttributeError:
queryset = concrete_model.objects.all
try:
return queryset(**kwargs).filter(**lookup).order_by(order)[0]
except IndexError:
pass
示例10: __init__
def __init__(self, *args, **kwargs):
"""
For subclasses that are registered with an Admin class
that doesn't implement fieldsets, add any extra model fields
to this instance's fieldsets. This mimics Django's behaviour of
adding all model fields when no fieldsets are defined on the
Admin class.
"""
super(ContentTypedAdmin, self).__init__(*args, **kwargs)
self.concrete_model = base_concrete_model(ContentTyped, self.model)
# Test that the fieldsets don't differ from the concrete admin's.
if (self.model is not self.concrete_model and
self.fieldsets == self.base_concrete_modeladmin.fieldsets):
# Make a copy so that we aren't modifying other Admin
# classes' fieldsets.
self.fieldsets = deepcopy(self.fieldsets)
# Insert each field between the publishing fields and nav
# fields. Do so in reverse order to retain the order of
# the model's fields.
model_fields = self.concrete_model._meta.get_fields()
concrete_field = '{concrete_model}_ptr'.format(
concrete_model=self.concrete_model.get_content_model_name())
exclude_fields = [f.name for f in model_fields] + [concrete_field]
try:
exclude_fields.extend(self.exclude)
except (AttributeError, TypeError):
pass
try:
exclude_fields.extend(self.form.Meta.exclude)
except (AttributeError, TypeError):
pass
fields = self.model._meta.fields + self.model._meta.many_to_many
for field in reversed(fields):
if field.name not in exclude_fields and field.editable:
if not hasattr(field, "translated_field"):
self.fieldsets[0][1]["fields"].insert(3, field.name)
示例11: save
def save(self, *args, **kwargs):
"""
Create a unique slug by appending an index.
"""
if not self.slug:
self.slug = self.get_slug()
# For custom content types, use the ``Page`` instance for
# slug lookup.
concrete_model = base_concrete_model(Slugged, self)
i = 0
while True:
if i > 0:
if i > 1:
self.slug = self.slug.rsplit("-", 1)[0]
self.slug = "%s-%s" % (self.slug, i)
qs = concrete_model.objects.all()
if self.id is not None:
qs = qs.exclude(id=self.id)
try:
qs.get(slug=self.slug)
except ObjectDoesNotExist:
break
i += 1
super(Slugged, self).save(*args, **kwargs)
示例12: get_content_models
def get_content_models(cls):
""" Return all subclasses of the concrete model. """
concrete_model = base_concrete_model(ContentTyped, cls)
return [m for m in apps.get_models()
if m is not concrete_model and issubclass(m, concrete_model)]