apis_core.relations package
Subpackages
Submodules
apis_core.relations.admin module
apis_core.relations.apps module
apis_core.relations.filtersets module
apis_core.relations.forms module
- class apis_core.relations.forms.CustomSelect2ListChoiceField(choice_list=None, required=True, widget=None, label=None, initial=None, help_text='', *args, **kwargs)[source]
Bases:
Select2ListChoiceField
We use a custom Select2ListChoiceField in our Relation form, because we don’t want the form value to be validated. The field uses the choices setting as a basis for validating, but our choices span over multiple querysets, so its easier to simply not validate (some validation happens in the clean method anyway).
Use a list to generate choices in a ChoiceField.
function that returns a list.
- class apis_core.relations.forms.RelationForm(*args, **kwargs)[source]
Bases:
GenericModelForm
This form overrides generic form for relation editing. Relations have generic relations to subj and obj, but we hide those ForeignKey form fields and instead show autocomplete choices fields.
Initialize the form and add the subj and obj fields using the generic apis_entities autocomplete with the correct parameters.
- class Meta[source]
Bases:
object
- fields = '__all__'
- widgets = {'obj_content_type': <django.forms.widgets.HiddenInput object>, 'obj_object_id': <django.forms.widgets.HiddenInput object>, 'subj_content_type': <django.forms.widgets.HiddenInput object>, 'subj_object_id': <django.forms.widgets.HiddenInput object>}
- base_fields = {}
- clean() dict [source]
We check if there are subj or obj fields in the form data and if so, we use the data to create objects for the real fields of the Relation
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
- class apis_core.relations.forms.RelationFormHX(*args, **kwargs)[source]
Bases:
RelationForm
A Relation form that sets a hx-post attribute to the form to make the htmx POST request use another route. We also pass a reverse boolean, wich gets passed on to the POST endpoint using url parameters. The POST endpoint then calculates the success_url based on the reverse state.
Initialize the form and add the subj and obj fields using the generic apis_entities autocomplete with the correct parameters.
- base_fields = {}
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
- property relation_name: str
apis_core.relations.models module
- class apis_core.relations.models.Relation(id, subj_content_type, subj_object_id, obj_content_type, obj_object_id)[source]
Bases:
Model
,GenericModel
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- iscousinof
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- ispartof
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- issiblingof
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- livesin
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- obj
Provide a generic many-to-one relation through the
content_type
andobject_id
fields.This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.
- obj_content_type
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- obj_content_type_id
- obj_object_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property obj_to_subj_text: str
- objects = <model_utils.managers.InheritanceManager object>
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- subj
Provide a generic many-to-one relation through the
content_type
andobject_id
fields.This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.
- subj_content_type
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- subj_content_type_id
- subj_object_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property subj_to_obj_text: str
apis_core.relations.querysets module
apis_core.relations.serializers module
- class apis_core.relations.serializers.RelationSerializer(*args, **kwargs)[source]
Bases:
SimpleObjectSerializer
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
apis_core.relations.tables module
- class apis_core.relations.tables.RelationColumn(*args, **kwargs)[source]
Bases:
CustomTemplateColumn
- template_name = 'columns/relation.html'
- verbose_name = ''
- class apis_core.relations.tables.RelationsListTable(data=None, order_by=None, orderable=None, empty_text=None, exclude=None, attrs=None, row_attrs=None, pinned_row_attrs=None, sequence=None, prefix=None, order_by_field=None, page_field=None, per_page_field=None, template_name=None, default=None, request=None, show_header=None, show_footer=True, extra_columns=None)[source]
Bases:
GenericTable
- class Meta[source]
Bases:
object
- attrs = {'class': 'table-sm'}
- exclude = ('desc',)
- sequence = ('...', 'view', 'edit', 'delete')
- base_columns = {'delete': <apis_core.generic.tables.DeleteColumn object>, 'edit': <apis_core.generic.tables.EditColumn object>, 'relation': <apis_core.relations.tables.RelationColumn object>, 'view': <apis_core.generic.tables.ViewColumn object>}
apis_core.relations.urls module
apis_core.relations.utils module
- apis_core.relations.utils.get_all_relation_subj_and_obj() list[ContentType] [source]
Return the model classes of any model that is in some way connected to a relation - either as obj or as subj
Returns: list[ContentType]: A list of unique ContentTypes for related models.
apis_core.relations.views module
- class apis_core.relations.views.CreateRelation(**kwargs)[source]
Bases:
Create
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- class apis_core.relations.views.CreateRelationForm(**kwargs)[source]
Bases:
CreateRelation
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- get_form_kwargs(*args, **kwargs) dict [source]
Return the keyword arguments for instantiating the form.
- template_name = 'relations/create_relation_form.html'