Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

use_a_custom_user_model.rst 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ==============================
  2. How to use a custom user model
  3. ==============================
  4. If you are using Django 1.5 or later, then you can specify a custom user model
  5. in your settings. Oscar will dynamically adjust the profile summary view and
  6. profile editing form to use the fields from your custom model.
  7. Before Django 1.5, the recommended technique for adding fields to users was to
  8. use a one-to-one "profile" model specified in the ``AUTH_PROFILE_MODULE``. As
  9. of Django 1.5, this setting is deprecated and will be removed_ in Django 1.7.
  10. Nevertheless, Oscar continues to support this setting and will add relevant
  11. fields to the profile form. Hence profiles can be used in combination with
  12. custom user models. That doesn't mean it's a good idea.
  13. .. _removed: https://docs.djangoproject.com/en/1.5/internals/deprecation/#id4
  14. Restrictions
  15. ------------
  16. Oscar does have some requirements on what fields a user model has. For
  17. instance, the auth backend requires a user to have an 'email' and 'password'
  18. field.
  19. Oscar 0.6 ships with its own abstract user model that supports the minimum
  20. fields and methods required for Oscar to work correctly. New Oscar projects are
  21. encouraged to subclass this User model.
  22. Migrations
  23. ----------
  24. When using a custom User model, the table name for that model will likely
  25. change. This breaks Oscar's migrations, throwing an error::
  26. Running migrations for analytics:
  27. - Migrating forwards to 0001_initial.
  28. > customer:0001_initial
  29. FATAL ERROR - The following SQL query failed: ALTER TABLE "customer_email" ADD CONSTRAINT "user_id_refs_id_2c2b8797" FOREIGN KEY ("user_id") REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED;
  30. The error was: relation "auth_user" does not exist
  31. Error in migration: customer:0001_initial
  32. DatabaseError: relation "auth_user" does not exist
  33. The recommended solution is to enforce the table name to be identical to the
  34. stock User model's one::
  35. # Custom User model
  36. class User(AbstractBaseUser, PermissionsMixin):
  37. [...]
  38. class Meta:
  39. db_table = 'auth_user'