EgbieAndersonUku1 / Fullstack-fruit-and-veg

Fullstack Fruit & Veg Shop: A web application developed with HTML, CSS, and JavaScript for the frontend, and Django for the backend. Features include user authentication, a product catalogue, shopping cart functionality, and order management. and much more
https://fullstack-fruit-and-veg.vercel.app
0 stars 0 forks source link

feat(authentication): create a custom user model and fix template issue #14

Closed EgbieAndersonUku1 closed 1 month ago

EgbieAndersonUku1 commented 1 month ago
  1. Create Custom User Model:

    • Developed a custom user model for authentication to replace Django's default User model.
    • The default User model in Django grants superuser status by default, which poses a security risk for applications where users should not have administrative privileges.
    • The custom user model removes superuser permissions, restricting users to their own account management.
  2. Template Override for Jazzmin Compatibility:

    • Modified the fieldset.html template to override the default one provided by Jazzmin.
    • Location: templates/admin/includes/fieldset.html (overrides venv/Lib/site-packages/jazzmin/templates/admin/includes/fieldset.html).
    • Reason: A recent Django update caused a TemplateSyntaxError due to the use of the length_is filter in Jazzmin's template.
    • Fix: Replaced instances of length_is with length == to match the updated Django syntax.
  3. Database Cleanup

    • Deleted the current database and recreated it using the exact same values used for the previous database. This will delete the old default user model and everything associated with it, while allowing me to use the same names stored in the .env file. It will also prepare it for the new custom user model
  4. Migration Cleanup:

    • Removed existing migration files under the account app folder, except for the __init__.py, to ensure compatibility with the new custom user model.
    • Ran python manage.py makemigrations and python manage.py migrate to apply the new changes.
  5. Superuser Creation:

    • Created a new superuser using the custom user model with python manage.py createsuperuser.
  6. User Model Management:

    • Users can be managed in two ways: - Using Django shell: python python manage.py shell from authentication.models import User user = User(username="username", email="some@email.com") user.set_password("password") user.save() - Using create_user method: python User.objects.create_user(username="username", email="some@gmail.com", password="password")
    • Admin interface access: Users can now be managed/add/deleted via the admin dashboard at http://127.0.0.1:8000/admin.

Notes:

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **fullstack-fruit-and-veg** | ⬜️ Ignored ([Inspect](https://vercel.com/egbies-projects/fullstack-fruit-and-veg/64iFGvn4tpPXKxnENozVzvSpe8N3)) | | | Aug 23, 2024 10:29pm |