1) Ensure your settings.py located project/project/ folder has your 'portfolio_app" listed under INSTALLED_APPS:
2) Navigate to Visual Studio and click on Extensions tab on the left side (or CTRL+SHIFT+X)
3) Install SQLITE Viewer:
4) Open models.py and copy and paste: (Ensure you indent as needed)
from django.db import models
Create your models here.
class Student(models.Model):
List of choices for major value in database, human readable name
MAJOR = (
('CSCI-BS', 'BS in Computer Science'),
('CPEN-BS', 'BS in Computer Engineering'),
('BIGD-BI', 'BI in Game Design and Development'),
('BICS-BI', 'BI in Computer Science'),
('BISC-BI', 'BI in Computer Security'),
('CSCI-BA', 'BA in Computer Science'),
('DASE-BS', 'BS in Data Analytics and Systems Engineering')
)
name = models.CharField(max_length=200)
email = models.CharField("UCCS Email", max_length=200)
major = models.CharField(max_length=200, choices=MAJOR, blank = True)
5) Open admin.py and copy and paste:
from django.contrib import admin
from .models import Student # Import the Student model from your models.py file
Register the Student model with the admin site
admin.site.register(Student)
6) Run the command: python3 manage.py makemigrations
9) Click on the Student drop-down from your admin tab and try to add a student. Notice the fields currently needing to be filled out are only name and email.
10) Open models.py again and copy the following:
from django.urls import reverse
Define default String to return the name for representing the Model object."
def __str__(self):
return self.name
#Returns the URL to access a particular instance of MyModelName.
#if you define this method then Django will automatically
#add a "View on Site" button to the model's record editing screens in the Admin site
def get_absolute_url(self):
return reverse('student-detail', args=[str(self.id)])
NOTE
Remove blank=true portion of Major to force the option to select a Major when creating a student.
11) Create a Student by filling out: Name, email, major.
12) Navigate to VS Studio and verify that the Name portion of Student is correct.
Creating Student Model
NOTE
1) Ensure your settings.py located project/project/ folder has your 'portfolio_app" listed under INSTALLED_APPS:
2) Navigate to Visual Studio and click on Extensions tab on the left side (or CTRL+SHIFT+X)
3) Install SQLITE Viewer:
4) Open models.py and copy and paste: (Ensure you indent as needed) from django.db import models
Create your models here.
class Student(models.Model):
List of choices for major value in database, human readable name
MAJOR = ( ('CSCI-BS', 'BS in Computer Science'), ('CPEN-BS', 'BS in Computer Engineering'), ('BIGD-BI', 'BI in Game Design and Development'), ('BICS-BI', 'BI in Computer Science'), ('BISC-BI', 'BI in Computer Security'), ('CSCI-BA', 'BA in Computer Science'), ('DASE-BS', 'BS in Data Analytics and Systems Engineering') ) name = models.CharField(max_length=200) email = models.CharField("UCCS Email", max_length=200) major = models.CharField(max_length=200, choices=MAJOR, blank = True)
5) Open admin.py and copy and paste: from django.contrib import admin from .models import Student # Import the Student model from your models.py file
Register the Student model with the admin site
admin.site.register(Student)
6) Run the command: python3 manage.py makemigrations
7) Run the command: python3 manage.py runserver
8) Navigate to: http://localhost:8000/admin/
NOTE
9) Click on the Student drop-down from your admin tab and try to add a student. Notice the fields currently needing to be filled out are only name and email.
10) Open models.py again and copy the following: from django.urls import reverse
Define default String to return the name for representing the Model object."
NOTE
11) Create a Student by filling out: Name, email, major.
12) Navigate to VS Studio and verify that the Name portion of Student is correct.
13) Once verified, navigate back to http://localhost:8000/admin/ and delete the student you created.
NOTE