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
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.
Template Override for Jazzmin Compatibility:
Modified the fieldset.html template to override the default one provided by Jazzmin.
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.
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
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.
Superuser Creation:
Created a new superuser using the custom user model with python manage.py createsuperuser.
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:
By default, Django hashes passwords before storing them in the database so there is no need to hash them. You can view the hashed password either in the admin dashboard by navigation to 127.0.0.1:8000/admin or by running the following commands within interpreted shell python manage.py shell which opens up a CLI interface that allows you to test your models within it :
Import the user model: python from authentication.models import User
Retrieve the user by username or email and access the password: python user = User.objects.get(username="username of account to find") # or user = User.objects.get(email="account email to find here") print(user.password)
Alternatively, use the filter method: python user = User.objects.filter(username="some username to find").first() print(user.password)
Create Custom User Model:
User
model.User
model in Django grants superuser status by default, which poses a security risk for applications where users should not have administrative privileges.Template Override for Jazzmin Compatibility:
fieldset.html
template to override the default one provided by Jazzmin.templates/admin/includes/fieldset.html
(overridesvenv/Lib/site-packages/jazzmin/templates/admin/includes/fieldset.html
).TemplateSyntaxError
due to the use of thelength_is
filter in Jazzmin's template.length_is
withlength ==
to match the updated Django syntax.Database Cleanup
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 modelMigration Cleanup:
account app
folder, except for the__init__.py
, to ensure compatibility with the new custom user model.python manage.py makemigrations
andpython manage.py migrate
to apply the new changes.Superuser Creation:
python manage.py createsuperuser
.User Model Management:
python python manage.py shell from authentication.models import User user = User(username="username", email="some@email.com") user.set_password("password") user.save()
- Usingcreate_user
method:python User.objects.create_user(username="username", email="some@gmail.com", password="password")
http://127.0.0.1:8000/admin
.Notes:
admin dashboard
by navigation to127.0.0.1:8000/admin
or by running the following commands within interpreted shellpython manage.py shell
which opens up a CLI interface that allows you to test your models within it :python from authentication.models import User
python user = User.objects.get(username="username of account to find") # or user = User.objects.get(email="account email to find here") print(user.password)
python user = User.objects.filter(username="some username to find").first() print(user.password)