| | 241 | # ModelAdmin Option Validation ################################################ |
|---|
| | 242 | |
|---|
| | 243 | >>> from django.contrib.admin.validation import validate |
|---|
| | 244 | >>> from django.conf import settings |
|---|
| | 245 | |
|---|
| | 246 | # Ensure validation only runs when DEBUG = True |
|---|
| | 247 | |
|---|
| | 248 | >>> settings.DEBUG = True |
|---|
| | 249 | |
|---|
| | 250 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 251 | ... raw_id_fields = 10 |
|---|
| | 252 | >>> site = AdminSite() |
|---|
| | 253 | >>> site.register(ValidationTestModel, ValidationTestModelAdmin) |
|---|
| | 254 | Traceback (most recent call last): |
|---|
| | 255 | ... |
|---|
| | 256 | ImproperlyConfigured: `ValidationTestModelAdmin.raw_id_fields` must be a list or tuple. |
|---|
| | 257 | |
|---|
| | 258 | >>> settings.DEBUG = False |
|---|
| | 259 | |
|---|
| | 260 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 261 | ... raw_id_fields = 10 |
|---|
| | 262 | >>> site = AdminSite() |
|---|
| | 263 | >>> site.register(ValidationTestModel, ValidationTestModelAdmin) |
|---|
| | 264 | |
|---|
| | 265 | # raw_id_fields |
|---|
| | 266 | |
|---|
| | 267 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 268 | ... raw_id_fields = 10 |
|---|
| | 269 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 270 | Traceback (most recent call last): |
|---|
| | 271 | ... |
|---|
| | 272 | ImproperlyConfigured: `ValidationTestModelAdmin.raw_id_fields` must be a list or tuple. |
|---|
| | 273 | |
|---|
| | 274 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 275 | ... raw_id_fields = ('non_existent_field',) |
|---|
| | 276 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 277 | Traceback (most recent call last): |
|---|
| | 278 | ... |
|---|
| | 279 | ImproperlyConfigured: `ValidationTestModelAdmin.raw_id_fields` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 280 | |
|---|
| | 281 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 282 | ... raw_id_fields = ('name',) |
|---|
| | 283 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 284 | Traceback (most recent call last): |
|---|
| | 285 | ... |
|---|
| | 286 | ImproperlyConfigured: `ValidationTestModelAdmin.raw_id_fields[0]`, `name` must be either a ForeignKey or ManyToManyField. |
|---|
| | 287 | |
|---|
| | 288 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 289 | ... raw_id_fields = ('users',) |
|---|
| | 290 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 291 | |
|---|
| | 292 | # fieldsets |
|---|
| | 293 | |
|---|
| | 294 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 295 | ... fieldsets = 10 |
|---|
| | 296 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 297 | Traceback (most recent call last): |
|---|
| | 298 | ... |
|---|
| | 299 | ImproperlyConfigured: `ValidationTestModelAdmin.fieldsets` must be a list or tuple. |
|---|
| | 300 | |
|---|
| | 301 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 302 | ... fieldsets = ({},) |
|---|
| | 303 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 304 | Traceback (most recent call last): |
|---|
| | 305 | ... |
|---|
| | 306 | ImproperlyConfigured: `ValidationTestModelAdmin.fieldsets[0]` must be a list or tuple. |
|---|
| | 307 | |
|---|
| | 308 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 309 | ... fieldsets = ((),) |
|---|
| | 310 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 311 | Traceback (most recent call last): |
|---|
| | 312 | ... |
|---|
| | 313 | ImproperlyConfigured: `ValidationTestModelAdmin.fieldsets[0]` does not have exactly two elements. |
|---|
| | 314 | |
|---|
| | 315 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 316 | ... fieldsets = (("General", ()),) |
|---|
| | 317 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 318 | Traceback (most recent call last): |
|---|
| | 319 | ... |
|---|
| | 320 | ImproperlyConfigured: `ValidationTestModelAdmin.fieldsets[0][1]` must be a dictionary. |
|---|
| | 321 | |
|---|
| | 322 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 323 | ... fieldsets = (("General", {}),) |
|---|
| | 324 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 325 | Traceback (most recent call last): |
|---|
| | 326 | ... |
|---|
| | 327 | ImproperlyConfigured: `fields` key is required in ValidationTestModelAdmin.fieldsets[0][1] field options dict. |
|---|
| | 328 | |
|---|
| | 329 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 330 | ... fieldsets = (("General", {"fields": ("non_existent_field",)}),) |
|---|
| | 331 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 332 | Traceback (most recent call last): |
|---|
| | 333 | ... |
|---|
| | 334 | ImproperlyConfigured: `ValidationTestModelAdmin.fieldsets[0][1]['fields']` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 335 | |
|---|
| | 336 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 337 | ... fieldsets = (("General", {"fields": ("name",)}),) |
|---|
| | 338 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 339 | |
|---|
| | 340 | # form |
|---|
| | 341 | |
|---|
| | 342 | >>> class FakeForm(object): |
|---|
| | 343 | ... pass |
|---|
| | 344 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 345 | ... form = FakeForm |
|---|
| | 346 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 347 | Traceback (most recent call last): |
|---|
| | 348 | ... |
|---|
| | 349 | ImproperlyConfigured: ValidationTestModelAdmin.form does not inherit from BaseModelForm. |
|---|
| | 350 | |
|---|
| | 351 | # filter_vertical |
|---|
| | 352 | |
|---|
| | 353 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 354 | ... filter_vertical = 10 |
|---|
| | 355 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 356 | Traceback (most recent call last): |
|---|
| | 357 | ... |
|---|
| | 358 | ImproperlyConfigured: `ValidationTestModelAdmin.filter_vertical` must be a list or tuple. |
|---|
| | 359 | |
|---|
| | 360 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 361 | ... filter_vertical = ("non_existent_field",) |
|---|
| | 362 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 363 | Traceback (most recent call last): |
|---|
| | 364 | ... |
|---|
| | 365 | ImproperlyConfigured: `ValidationTestModelAdmin.filter_vertical` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 366 | |
|---|
| | 367 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 368 | ... filter_vertical = ("name",) |
|---|
| | 369 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 370 | Traceback (most recent call last): |
|---|
| | 371 | ... |
|---|
| | 372 | ImproperlyConfigured: `ValidationTestModelAdmin.filter_vertical[0]` must be a ManyToManyField. |
|---|
| | 373 | |
|---|
| | 374 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 375 | ... filter_vertical = ("users",) |
|---|
| | 376 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 377 | |
|---|
| | 378 | # filter_horizontal |
|---|
| | 379 | |
|---|
| | 380 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 381 | ... filter_horizontal = 10 |
|---|
| | 382 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 383 | Traceback (most recent call last): |
|---|
| | 384 | ... |
|---|
| | 385 | ImproperlyConfigured: `ValidationTestModelAdmin.filter_horizontal` must be a list or tuple. |
|---|
| | 386 | |
|---|
| | 387 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 388 | ... filter_horizontal = ("non_existent_field",) |
|---|
| | 389 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 390 | Traceback (most recent call last): |
|---|
| | 391 | ... |
|---|
| | 392 | ImproperlyConfigured: `ValidationTestModelAdmin.filter_horizontal` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 393 | |
|---|
| | 394 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 395 | ... filter_horizontal = ("name",) |
|---|
| | 396 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 397 | Traceback (most recent call last): |
|---|
| | 398 | ... |
|---|
| | 399 | ImproperlyConfigured: `ValidationTestModelAdmin.filter_horizontal[0]` must be a ManyToManyField. |
|---|
| | 400 | |
|---|
| | 401 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 402 | ... filter_horizontal = ("users",) |
|---|
| | 403 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 404 | |
|---|
| | 405 | # radio_fields |
|---|
| | 406 | |
|---|
| | 407 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 408 | ... radio_fields = () |
|---|
| | 409 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 410 | Traceback (most recent call last): |
|---|
| | 411 | ... |
|---|
| | 412 | ImproperlyConfigured: `ValidationTestModelAdmin.radio_fields` must be a dictionary. |
|---|
| | 413 | |
|---|
| | 414 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 415 | ... radio_fields = {"non_existent_field": None} |
|---|
| | 416 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 417 | Traceback (most recent call last): |
|---|
| | 418 | ... |
|---|
| | 419 | ImproperlyConfigured: `ValidationTestModelAdmin.radio_fields` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 420 | |
|---|
| | 421 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 422 | ... radio_fields = {"name": None} |
|---|
| | 423 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 424 | Traceback (most recent call last): |
|---|
| | 425 | ... |
|---|
| | 426 | ImproperlyConfigured: `ValidationTestModelAdmin.radio_fields['name']` is neither an instance of ForeignKey nor does have choices set. |
|---|
| | 427 | |
|---|
| | 428 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 429 | ... radio_fields = {"state": None} |
|---|
| | 430 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 431 | Traceback (most recent call last): |
|---|
| | 432 | ... |
|---|
| | 433 | ImproperlyConfigured: `ValidationTestModelAdmin.radio_fields['state']` is neither admin.HORIZONTAL nor admin.VERTICAL. |
|---|
| | 434 | |
|---|
| | 435 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 436 | ... radio_fields = {"state": VERTICAL} |
|---|
| | 437 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 438 | |
|---|
| | 439 | # prepopulated_fields |
|---|
| | 440 | |
|---|
| | 441 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 442 | ... prepopulated_fields = () |
|---|
| | 443 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 444 | Traceback (most recent call last): |
|---|
| | 445 | ... |
|---|
| | 446 | ImproperlyConfigured: `ValidationTestModelAdmin.prepopulated_fields` must be a dictionary. |
|---|
| | 447 | |
|---|
| | 448 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 449 | ... prepopulated_fields = {"non_existent_field": None} |
|---|
| | 450 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 451 | Traceback (most recent call last): |
|---|
| | 452 | ... |
|---|
| | 453 | ImproperlyConfigured: `ValidationTestModelAdmin.prepopulated_fields` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 454 | |
|---|
| | 455 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 456 | ... prepopulated_fields = {"slug": ("non_existent_field",)} |
|---|
| | 457 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 458 | Traceback (most recent call last): |
|---|
| | 459 | ... |
|---|
| | 460 | ImproperlyConfigured: `ValidationTestModelAdmin.prepopulated_fields['non_existent_field'][0]` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 461 | |
|---|
| | 462 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 463 | ... prepopulated_fields = {"users": ("name",)} |
|---|
| | 464 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 465 | Traceback (most recent call last): |
|---|
| | 466 | ... |
|---|
| | 467 | ImproperlyConfigured: `ValidationTestModelAdmin.prepopulated_fields['users']` is either a DateTimeField, ForeignKey or ManyToManyField. This isn't allowed. |
|---|
| | 468 | |
|---|
| | 469 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 470 | ... prepopulated_fields = {"slug": ("name",)} |
|---|
| | 471 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 472 | |
|---|
| | 473 | # list_display |
|---|
| | 474 | |
|---|
| | 475 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 476 | ... list_display = 10 |
|---|
| | 477 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 478 | Traceback (most recent call last): |
|---|
| | 479 | ... |
|---|
| | 480 | ImproperlyConfigured: `ValidationTestModelAdmin.list_display` must be a list or tuple. |
|---|
| | 481 | |
|---|
| | 482 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 483 | ... list_display = ('non_existent_field',) |
|---|
| | 484 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 485 | Traceback (most recent call last): |
|---|
| | 486 | ... |
|---|
| | 487 | ImproperlyConfigured: `ValidationTestModelAdmin.list_display[0]` refers to `non_existent_field` that is neither a field, method or property of model `ValidationTestModel`. |
|---|
| | 488 | |
|---|
| | 489 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 490 | ... list_display = ('users',) |
|---|
| | 491 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 492 | Traceback (most recent call last): |
|---|
| | 493 | ... |
|---|
| | 494 | ImproperlyConfigured: `ValidationTestModelAdmin.list_display[0]`, `users` is a ManyToManyField which is not supported. |
|---|
| | 495 | |
|---|
| | 496 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 497 | ... list_display = ('name',) |
|---|
| | 498 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 499 | |
|---|
| | 500 | # list_display_links |
|---|
| | 501 | |
|---|
| | 502 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 503 | ... list_display_links = 10 |
|---|
| | 504 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 505 | Traceback (most recent call last): |
|---|
| | 506 | ... |
|---|
| | 507 | ImproperlyConfigured: `ValidationTestModelAdmin.list_display_links` must be a list or tuple. |
|---|
| | 508 | |
|---|
| | 509 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 510 | ... list_display_links = ('non_existent_field',) |
|---|
| | 511 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 512 | Traceback (most recent call last): |
|---|
| | 513 | ... |
|---|
| | 514 | ImproperlyConfigured: `ValidationTestModelAdmin.list_display_links[0]` refers to `non_existent_field` that is neither a field, method or property of model `ValidationTestModel`. |
|---|
| | 515 | |
|---|
| | 516 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 517 | ... list_display_links = ('name',) |
|---|
| | 518 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 519 | Traceback (most recent call last): |
|---|
| | 520 | ... |
|---|
| | 521 | ImproperlyConfigured: `ValidationTestModelAdmin.list_display_links[0]`refers to `name` which is not defined in `list_display`. |
|---|
| | 522 | |
|---|
| | 523 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 524 | ... list_display = ('name',) |
|---|
| | 525 | ... list_display_links = ('name',) |
|---|
| | 526 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 527 | |
|---|
| | 528 | # list_filter |
|---|
| | 529 | |
|---|
| | 530 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 531 | ... list_filter = 10 |
|---|
| | 532 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 533 | Traceback (most recent call last): |
|---|
| | 534 | ... |
|---|
| | 535 | ImproperlyConfigured: `ValidationTestModelAdmin.list_filter` must be a list or tuple. |
|---|
| | 536 | |
|---|
| | 537 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 538 | ... list_filter = ('non_existent_field',) |
|---|
| | 539 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 540 | Traceback (most recent call last): |
|---|
| | 541 | ... |
|---|
| | 542 | ImproperlyConfigured: `ValidationTestModelAdmin.list_filter[0]` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 543 | |
|---|
| | 544 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 545 | ... list_filter = ('is_active',) |
|---|
| | 546 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 547 | |
|---|
| | 548 | # list_per_page |
|---|
| | 549 | |
|---|
| | 550 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 551 | ... list_per_page = 'hello' |
|---|
| | 552 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 553 | Traceback (most recent call last): |
|---|
| | 554 | ... |
|---|
| | 555 | ImproperlyConfigured: `ValidationTestModelAdmin.list_per_page` should be a integer. |
|---|
| | 556 | |
|---|
| | 557 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 558 | ... list_per_page = 100 |
|---|
| | 559 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 560 | |
|---|
| | 561 | # search_fields |
|---|
| | 562 | |
|---|
| | 563 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 564 | ... search_fields = 10 |
|---|
| | 565 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 566 | Traceback (most recent call last): |
|---|
| | 567 | ... |
|---|
| | 568 | ImproperlyConfigured: `ValidationTestModelAdmin.search_fields` must be a list or tuple. |
|---|
| | 569 | |
|---|
| | 570 | # date_hierarchy |
|---|
| | 571 | |
|---|
| | 572 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 573 | ... date_hierarchy = 'non_existent_field' |
|---|
| | 574 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 575 | Traceback (most recent call last): |
|---|
| | 576 | ... |
|---|
| | 577 | ImproperlyConfigured: `ValidationTestModelAdmin.date_hierarchy` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 578 | |
|---|
| | 579 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 580 | ... date_hierarchy = 'name' |
|---|
| | 581 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 582 | Traceback (most recent call last): |
|---|
| | 583 | ... |
|---|
| | 584 | ImproperlyConfigured: `ValidationTestModelAdmin.date_hierarchy is neither an instance of DateField nor DateTimeField. |
|---|
| | 585 | |
|---|
| | 586 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 587 | ... date_hierarchy = 'pub_date' |
|---|
| | 588 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 589 | |
|---|
| | 590 | # ordering |
|---|
| | 591 | |
|---|
| | 592 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 593 | ... ordering = 10 |
|---|
| | 594 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 595 | Traceback (most recent call last): |
|---|
| | 596 | ... |
|---|
| | 597 | ImproperlyConfigured: `ValidationTestModelAdmin.ordering` must be a list or tuple. |
|---|
| | 598 | |
|---|
| | 599 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 600 | ... ordering = ('non_existent_field',) |
|---|
| | 601 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 602 | Traceback (most recent call last): |
|---|
| | 603 | ... |
|---|
| | 604 | ImproperlyConfigured: `ValidationTestModelAdmin.ordering[0]` refers to field `non_existent_field` that is missing from model `ValidationTestModel`. |
|---|
| | 605 | |
|---|
| | 606 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 607 | ... ordering = ('?', 'name') |
|---|
| | 608 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 609 | Traceback (most recent call last): |
|---|
| | 610 | ... |
|---|
| | 611 | ImproperlyConfigured: `ValidationTestModelAdmin.ordering` has the random ordering marker `?`, but contains other fields as well. Please either remove `?` or the other fields. |
|---|
| | 612 | |
|---|
| | 613 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 614 | ... ordering = ('name',) |
|---|
| | 615 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 616 | |
|---|
| | 617 | # list_select_related |
|---|
| | 618 | |
|---|
| | 619 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 620 | ... list_select_related = 1 |
|---|
| | 621 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 622 | Traceback (most recent call last): |
|---|
| | 623 | ... |
|---|
| | 624 | ImproperlyConfigured: `ValidationTestModelAdmin.list_select_related` should be a boolean. |
|---|
| | 625 | |
|---|
| | 626 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 627 | ... list_select_related = False |
|---|
| | 628 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 629 | |
|---|
| | 630 | # save_as |
|---|
| | 631 | |
|---|
| | 632 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 633 | ... save_as = 1 |
|---|
| | 634 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 635 | Traceback (most recent call last): |
|---|
| | 636 | ... |
|---|
| | 637 | ImproperlyConfigured: `ValidationTestModelAdmin.save_as` should be a boolean. |
|---|
| | 638 | |
|---|
| | 639 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 640 | ... save_as = True |
|---|
| | 641 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 642 | |
|---|
| | 643 | # save_on_top |
|---|
| | 644 | |
|---|
| | 645 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 646 | ... save_on_top = 1 |
|---|
| | 647 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 648 | Traceback (most recent call last): |
|---|
| | 649 | ... |
|---|
| | 650 | ImproperlyConfigured: `ValidationTestModelAdmin.save_on_top` should be a boolean. |
|---|
| | 651 | |
|---|
| | 652 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 653 | ... save_on_top = True |
|---|
| | 654 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 655 | |
|---|
| | 656 | # inlines |
|---|
| | 657 | |
|---|
| | 658 | >>> from django.contrib.admin.options import TabularInline |
|---|
| | 659 | |
|---|
| | 660 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 661 | ... inlines = 10 |
|---|
| | 662 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 663 | Traceback (most recent call last): |
|---|
| | 664 | ... |
|---|
| | 665 | ImproperlyConfigured: `ValidationTestModelAdmin.inlines` must be a list or tuple. |
|---|
| | 666 | |
|---|
| | 667 | >>> class ValidationTestInline(object): |
|---|
| | 668 | ... pass |
|---|
| | 669 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 670 | ... inlines = [ValidationTestInline] |
|---|
| | 671 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 672 | Traceback (most recent call last): |
|---|
| | 673 | ... |
|---|
| | 674 | ImproperlyConfigured: `ValidationTestModelAdmin.inlines[0]` does not inherit from BaseModelAdmin. |
|---|
| | 675 | |
|---|
| | 676 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 677 | ... pass |
|---|
| | 678 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 679 | ... inlines = [ValidationTestInline] |
|---|
| | 680 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 681 | Traceback (most recent call last): |
|---|
| | 682 | ... |
|---|
| | 683 | ImproperlyConfigured: `model` is a required attribute of `ValidationTestModelAdmin.inlines[0]`. |
|---|
| | 684 | |
|---|
| | 685 | >>> class SomethingBad(object): |
|---|
| | 686 | ... pass |
|---|
| | 687 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 688 | ... model = SomethingBad |
|---|
| | 689 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 690 | ... inlines = [ValidationTestInline] |
|---|
| | 691 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 692 | Traceback (most recent call last): |
|---|
| | 693 | ... |
|---|
| | 694 | ImproperlyConfigured: `ValidationTestModelAdmin.inlines[0].model` does not inherit from models.Model. |
|---|
| | 695 | |
|---|
| | 696 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 697 | ... model = ValidationTestInlineModel |
|---|
| | 698 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 699 | ... inlines = [ValidationTestInline] |
|---|
| | 700 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 701 | |
|---|
| | 702 | # fields |
|---|
| | 703 | |
|---|
| | 704 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 705 | ... model = ValidationTestInlineModel |
|---|
| | 706 | ... fields = 10 |
|---|
| | 707 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 708 | ... inlines = [ValidationTestInline] |
|---|
| | 709 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 710 | Traceback (most recent call last): |
|---|
| | 711 | ... |
|---|
| | 712 | ImproperlyConfigured: `ValidationTestInline.fields` must be a list or tuple. |
|---|
| | 713 | |
|---|
| | 714 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 715 | ... model = ValidationTestInlineModel |
|---|
| | 716 | ... fields = ("non_existent_field",) |
|---|
| | 717 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 718 | ... inlines = [ValidationTestInline] |
|---|
| | 719 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 720 | Traceback (most recent call last): |
|---|
| | 721 | ... |
|---|
| | 722 | ImproperlyConfigured: `ValidationTestInline.fields` refers to field `non_existent_field` that is missing from model `ValidationTestInlineModel`. |
|---|
| | 723 | |
|---|
| | 724 | # fk_name |
|---|
| | 725 | |
|---|
| | 726 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 727 | ... model = ValidationTestInlineModel |
|---|
| | 728 | ... fk_name = "non_existent_field" |
|---|
| | 729 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 730 | ... inlines = [ValidationTestInline] |
|---|
| | 731 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 732 | Traceback (most recent call last): |
|---|
| | 733 | ... |
|---|
| | 734 | ImproperlyConfigured: `ValidationTestInline.fk_name` refers to field `non_existent_field` that is missing from model `ValidationTestInlineModel`. |
|---|
| | 735 | |
|---|
| | 736 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 737 | ... model = ValidationTestInlineModel |
|---|
| | 738 | ... fk_name = "parent" |
|---|
| | 739 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 740 | ... inlines = [ValidationTestInline] |
|---|
| | 741 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 742 | |
|---|
| | 743 | # extra |
|---|
| | 744 | |
|---|
| | 745 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 746 | ... model = ValidationTestInlineModel |
|---|
| | 747 | ... extra = "hello" |
|---|
| | 748 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 749 | ... inlines = [ValidationTestInline] |
|---|
| | 750 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 751 | Traceback (most recent call last): |
|---|
| | 752 | ... |
|---|
| | 753 | ImproperlyConfigured: `ValidationTestInline.extra` should be a integer. |
|---|
| | 754 | |
|---|
| | 755 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 756 | ... model = ValidationTestInlineModel |
|---|
| | 757 | ... extra = 2 |
|---|
| | 758 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 759 | ... inlines = [ValidationTestInline] |
|---|
| | 760 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 761 | |
|---|
| | 762 | # max_num |
|---|
| | 763 | |
|---|
| | 764 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 765 | ... model = ValidationTestInlineModel |
|---|
| | 766 | ... max_num = "hello" |
|---|
| | 767 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 768 | ... inlines = [ValidationTestInline] |
|---|
| | 769 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 770 | Traceback (most recent call last): |
|---|
| | 771 | ... |
|---|
| | 772 | ImproperlyConfigured: `ValidationTestInline.max_num` should be a integer. |
|---|
| | 773 | |
|---|
| | 774 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 775 | ... model = ValidationTestInlineModel |
|---|
| | 776 | ... max_num = 2 |
|---|
| | 777 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 778 | ... inlines = [ValidationTestInline] |
|---|
| | 779 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 780 | |
|---|
| | 781 | # formset |
|---|
| | 782 | |
|---|
| | 783 | >>> class FakeFormSet(object): |
|---|
| | 784 | ... pass |
|---|
| | 785 | >>> class ValidationTestInline(TabularInline): |
|---|
| | 786 | ... model = ValidationTestInlineModel |
|---|
| | 787 | ... formset = FakeFormSet |
|---|
| | 788 | >>> class ValidationTestModelAdmin(ModelAdmin): |
|---|
| | 789 | ... inlines = [ValidationTestInline] |
|---|
| | 790 | >>> validate(ValidationTestModelAdmin, ValidationTestModel) |
|---|
| | 791 | Traceback (most recent call last): |
|---|
| | 792 | ... |
|---|
| | 793 | ImproperlyConfigured: `ValidationTestInline.formset` does not inherit from BaseInlineFormset. |
|---|
| | 794 | |
|---|