mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2025-04-27 10:11:24 +08:00
Added subject field to transaction and course field to customuser
This commit is contained in:
parent
0b1c065a80
commit
2ddc9da179
12 changed files with 55 additions and 52 deletions
|
@ -9,7 +9,7 @@ class CustomUserAdmin(UserAdmin):
|
|||
list_display = UserAdmin.list_display + \
|
||||
('is_technician', 'is_teacher', 'id')
|
||||
fieldsets = UserAdmin.fieldsets + (
|
||||
(None, {'fields': ('is_technician', 'is_teacher')}),
|
||||
(None, {'fields': ('is_technician', 'is_teacher', 'course')}),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.7 on 2023-12-08 14:41
|
||||
# Generated by Django 4.2.7 on 2023-12-29 10:21
|
||||
|
||||
import accounts.models
|
||||
import django.contrib.auth.models
|
||||
|
@ -32,6 +32,7 @@ class Migration(migrations.Migration):
|
|||
('is_active', models.BooleanField(default=False)),
|
||||
('is_technician', models.BooleanField(default=False)),
|
||||
('is_teacher', models.BooleanField(default=False)),
|
||||
('course', models.CharField(choices=[('BS Chemistry', 'BS Chemistry'), ('BS Food Technology', 'BS Food Technology'), ('BS Applied Physics', 'BS Applied Physics'), ('BS Environmental Science', 'BS Environmental Science')], default=None, max_length=60, null=True)),
|
||||
('avatar', models.ImageField(null=True, upload_to=accounts.models.CustomUser._get_upload_to)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
|
|
|
@ -39,6 +39,16 @@ class CustomUser(AbstractUser):
|
|||
is_active = models.BooleanField(default=False)
|
||||
is_technician = models.BooleanField(default=False)
|
||||
is_teacher = models.BooleanField(default=False)
|
||||
|
||||
COURSE_CHOICES = (
|
||||
('BS Chemistry', 'BS Chemistry'),
|
||||
('BS Food Technology', 'BS Food Technology'),
|
||||
('BS Applied Physics', 'BS Applied Physics'),
|
||||
('BS Environmental Science', 'BS Environmental Science'),
|
||||
)
|
||||
|
||||
course = models.CharField(
|
||||
max_length=60, null=True, choices=COURSE_CHOICES, default=None)
|
||||
avatar = models.ImageField(upload_to=_get_upload_to, null=True)
|
||||
|
||||
@property
|
||||
|
@ -108,7 +118,7 @@ def create_superuser(sender, **kwargs):
|
|||
if not User.objects.filter(username=username).exists():
|
||||
# Create the superuser with is_active set to False
|
||||
user = User.objects.create_user(
|
||||
username=username, email=email, password=password, first_name=first_name, last_name=last_name)
|
||||
username=username, email=email, password=password, first_name=first_name, last_name=last_name, course="BS Chemistry")
|
||||
|
||||
# Activate the user
|
||||
user.is_active = True
|
||||
|
|
|
@ -24,12 +24,14 @@ class CustomUserSerializer(BaseUserSerializer):
|
|||
|
||||
class UserRegistrationSerializer(serializers.ModelSerializer):
|
||||
email = serializers.EmailField(required=True)
|
||||
course = serializers.ChoiceField(
|
||||
choices=CustomUser.COURSE_CHOICES, required=True)
|
||||
password = serializers.CharField(
|
||||
write_only=True, style={'input_type': 'password', 'placeholder': 'Password'})
|
||||
|
||||
class Meta:
|
||||
model = CustomUser # Use your custom user model here
|
||||
fields = ('username', 'email', 'password', 'avatar',
|
||||
fields = ('username', 'email', 'password', 'avatar', 'course',
|
||||
'first_name', 'last_name')
|
||||
read_only_fields = ('is_teacher', 'is_technician')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue