3

I'm writing tests for Django project with django-guardian. Fixture for permissions look like:

- fields:
    content_type: 10
    object_pk: '2'
    permission: 22
    user: 1
  model: guardian.userobjectpermission
  pk: 1

Is it safe to reference content_type and permission by id? Or are ids going to change (i.e. when I add extra permission/model)?

What is the best method for referencing objects which are loaded automatically?

Domen Blenkuš
  • 2,182
  • 1
  • 21
  • 29

1 Answers1

11

You should be able to use natural keys to reference the content_type and permission values.

- fields:
    content_type: [<app_label>, <model>],
    object_pk: '2'
    permission: [<permission_codename>, <app_label>, <model>],
    user: 1
  model: guardian.userobjectpermission
  pk: 1
Alasdair
  • 298,606
  • 55
  • 578
  • 516