Django Model Cruddals¶
A base class to generating a GraphQL schema with CRUDDALS operations for a Django model using Cruddals.
This class is designed to be used as a base class for Django models. GraphQL types and resolvers are generated automatically based on the provided Django model.
To use this class, define a subclass and include a Meta
class with the required attributes.
Example Usage:¶
from graphene_django_cruddals import DjangoModelCruddals
from your_django_app.models import YourModel
class YourModelCruddals(DjangoModelCruddals):
class Meta:
model = YourModel
... # Other options
from graphene_django_cruddals import DjangoModelCruddals
from your_django_app.models import YourModel
class YourModelCruddals(DjangoModelCruddals):
class Meta:
model = YourModel
functions = ("create", "read", "update", "delete", "deactivate", "activate", "list", "search")
# exclude_functions = ("create",)
prefix = "New"
suffix = "Suffix"
cruddals_interfaces = (CustomCruddalsInterface,)
# exclude_cruddals_interfaces = ("CustomCruddalsInterface",)
# registry = your_registry
field_for_activate_deactivate = "is_enabled"
Meta Class Options:¶
Note
These options can also be seen below in the definition of __init_subclass_with_meta__
method.
*model (DjangoModel):* The Django model class to be used for generating CRUDDALS operations.
*config (CruddalsBuilderConfig, optional):* Configuration object for customizing the behavior of the CRUDDALS operations. Defaults and recommended to None.
*functions (Tuple[FunctionType, ...], optional):* A tuple of functions ('create', 'read', 'update', 'delete', 'deactivate', 'activate', 'list', 'search') to be included in the generated GraphQL Schema. Defaults to None.
*exclude_functions (Tuple[FunctionType, ...], optional):* A tuple of functions to be excluded from the generated GraphQL Schema. Defaults to None.
*prefix (str, optional):* A prefix to be added to the generated GraphQL Types name. Defaults to "".
*suffix (str, optional):* A suffix to be added to the generated GraphQL Types name. Defaults to "".
*cruddals_interfaces (Tuple[Type[Any], ...], optional):* A tuple of additional Cruddals interfaces to be implemented by the generated GraphQL Schema. Defaults to ().
*exclude_cruddals_interfaces (Tuple[str, ...], optional):* A tuple of interface names to be excluded if `DjangoAppCruddals` or `DjangoProjectCruddals` is used. Defaults to ().
*registry (RegistryGlobal, optional):* The global registry object to be used for registering the generated GraphQL Schema. Defaults to None.
*field_for_activate_deactivate (str, optional):* The name of the field used for activating/deactivating the object. Defaults to "is_active".
Source code in graphene_django_cruddals/main.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
__init_subclass_with_meta__
classmethod
¶
__init_subclass_with_meta__(
model,
config=None,
functions=None,
exclude_functions=None,
prefix="",
suffix="",
cruddals_interfaces=(),
exclude_cruddals_interfaces=(),
registry=None,
field_for_activate_deactivate="is_active",
**kwargs
)
This method is called automatically when a subclass with a Meta
class is defined. There is no need to call this method directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Model
|
The Django model class to be used for generate CRUDDALS operations. |
required |
config |
CruddalsBuilderConfig
|
The configuration object for customizing the behavior of the CRUDDALS operations. Defaults and recommended to None. |
None
|
functions |
Tuple[FunctionType, ...]
|
A tuple of strings with the name of functions ('create', 'read', 'update', 'delete', 'deactivate', 'activate', 'list', 'search') to be included in the generated GraphQL Schema. Defaults to None, in which case all functions will be included. |
None
|
exclude_functions |
Tuple[FunctionType, ...]
|
A tuple of functions to be excluded from the generated GraphQL Schema. Defaults to None. |
None
|
prefix |
str
|
A prefix to be added to the generated GraphQL Types name. Defaults to "", in which case the model name will be used as is. |
''
|
suffix |
str
|
A suffix to be added to the generated GraphQL Types name. Defaults to "", in which case the model name will be used as is. |
''
|
cruddals_interfaces |
Tuple[Type[Any], ...]
|
A tuple of additional Cruddals interfaces to be implemented by the generated GraphQL Schema. Defaults to (). |
()
|
exclude_cruddals_interfaces |
Tuple[str, ...]
|
A tuple of interface names to be excluded from the generated GraphQL Schema. Defaults to (). |
()
|
registry |
RegistryGlobal
|
The global registry object to be used for registering the generated GraphQL Schema. Defaults to None, in which case a global registry will be used. |
None
|
field_for_activate_deactivate |
str
|
The name of the field used for activating/deactivating the object. Defaults to "is_active". |
'is_active'
|
Raises:
Type | Description |
---|---|
AssertionError
|
If the |
Source code in graphene_django_cruddals/main.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|