Contains a decorator that can be used to add xml serialization to django models as a method. In effect it adds an __xml__ method to both the model and the queryset used in the model.
adds an __xml__ method to both the queryset as the model class.
usage:
from easymode.tree.xml.decorators import toxml
@toxml
class Foo(models.ModelAdmin):
title = models.CharField(max_length=255)
content = TextField()
class Bar(models.ModelAdmin):
foo = models.ForeignKey(Foo, related_name=bars)
label = models.CharField(233)
The Foo model has now gained a __xml__ method on both itself as on the queryset it produces. Calling it will produce hierarchical xml, where all inverse relations are followed. (Except for manytomany fields, they are not supported).
Classes to support overriding the default queryset used in django models. These classes add a recursive __xml__ method to a django model’s queryset
Can be used to combine multiple querysets and turn them into xml in one go.
usage:
from easymode.tree import xml
from example.foobar.models import *
foos = Foo.objects.all()
bars = Bar.objects.all()
foobars = XmlQuerySetChain(foos, bars)
xml_string = xml(foobars)
You can also pass an XmlQuerySetChain into easymode.xslt.response.render_to_response.
Parameters: | querysets – a list of querysets that should combined into a single xml. |
---|
Contains a modeladmin class that shows links to all related items in its change_view.
If you want to use InvisibleModelAdmin make sure easymode comes before django.contrib.admin in the INSTALLED_APPS because it has to override admin/index.html to make it work.
An admin class that display links to related items.
This class is deprecated, please use easymode.tree.admin.abstract.LinkInline, easymode.tree.admin.abstract.LinkedItemAdmin instead.
This can be used for hierarchies of object deeper then 3 levels, where InlineModelAdmin can not be used anymore, but the parent/child relation is still there.
usage:
from easymode.tree.admin.relation import ForeignKeyAwareModelAdmin
class SomeAdmin(ForeignKeyAwareModelAdmin):
children = [SomeModelThatPointsToUs, AnotherModelThatPointsTous]
invisible_in_admin = False
admin.site.register(SomeModelWithLotsOfRelations, SomeAdmin)
This will add the SomeModelThatPointsToUs and AnotherModelThatPointsTous to the SomeModelWithLotsOfRelations admin interface and you can add these children or edit them there.
See InvisibleModelAdmin if you want to hide the admin interface for SomeModelThatPointsToUs and AnotherModelThatPointsTous admin interface from the admin listing.
If auto_aware is true, the admin will find out for itself which models are child nodes, by inspecting it’s managers.
To have sane breadcrumbs if the ForeignKeyAwareModelAdmin is used as child of another ForeignKeyAwareModelAdmin and make the save button return to the parent instead of the app listing, the parent_link should be set.
It must be set to the name of the ForeignKey that points to the parent.
If the order of the children should be changed or not all children should be displayed, you can specify the children manually.
children should be set to a list of models that are child nodes of the model class that this admin class makes editable:
The ForeignKeyAwareModelAdmin will not be shown in the admin listing if this value is True. The default is True.
An admin class that can be used as admin for children of ForeignKeyAwareModelAdmin.
This way they will be hidden in the admin interface so they can only be accessed via ForeignKeyAwareModelAdmin. usage:
from django.db import models
from django.contrib import admin
from easymode.tree.admin.relation import *
class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bars')
label = models.CharField(max_length=255)
class BarAdmin(InvisibleModelAdmin):
model = Bar
parent_link = 'foo'
admin.site.register(Bar, BarAdmin)
When InvisibleModelAdmin is used, it is nolonger displayed in the admin listing as an editable model. To have sane breadcrumbs and make the save button return to the parent instead of the app listing, the parent_link should be set.
It must be set to the name of the ForeignKey that points to the parent.
A base class for an admin inline that will render as links to the change_view. This means you have to also register the model you are inlining with a non-inline ModelAdmin:
class BottomAdmin(InvisibleModelAdmin):
parent_link = 'top'
class BottomLinkInline(LinkInline):
fields = ('top',)
model = BottomModel
It is mandatory to set the fields or fieldsets attribute of a class extending LinkInline. If you don’t, all the fields will be show, instead of only the change or add button. Ofcourse it can’t hurt to add some read_only_fields to add some context.
alias of RecursiveInlineFormSet
This class should be used as the base class for all admin classes that have LinkInline inlines:
class TopAdmin(LinkedItemAdmin):
inlines = [BottomLinkInline]
Also it can be used to make save return to a parent model in a tree context. You could also use InvisibleModelAdmin, and then it would also not be shown in the admin app list.
To have sane breadcrumbs if the LinkedItemAdmin is used as child of another LinkedItemAdmin and make the save button return to the parent instead of the app listing, the parent_link should be set.
It must be set to the name of the ForeignKey that points to the parent.
functionality for finding inverse foreign key relations in model classes
find all DefaultFieldDescriptor in obj.
Parameters: | obj – A model instance or class. |
---|
finds all ForeignRelatedObjectsDescriptor in obj.
Parameters: | obj – A model instance or class. |
---|
Finds all the ReverseGenericRelatedObjectsDescriptor in obj.
Parameters: | obj – A model instance or class. |
---|
finds all SingleRelatedObjectDescriptor in obj.
Parameters: | obj – A model instance or class. |
---|