The Course App

How to create and register Django models

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $15

Modified files

app/models.py
--- 
+++ 
@@ -1,3 +1,26 @@
 from django.db import models
+from django.contrib.auth.models import AbstractUser

-# Create your models here.
+
+ARTICLE_STATUS = (
+    ("draft", "draft"),
+    ("inprogress", "in progress"),
+    ("published", "published"),
+)
+
+
+class UserProfile(AbstractUser):
+    pass
+
+class Article(models.Model):
+    title = models.CharField(max_length=100)
+    content = models.TextField(blank=True, default="")
+    word_count = models.IntegerField()
+    twitter_post = models.TextField(blank=True, default="")
+    status = models.CharField(
+        max_length=20,
+        choices=ARTICLE_STATUS,
+        default="draft",
+    )
+    created_at = models.DateTimeField(auto_now_add=True)
+    updated_at = models.DateTimeField(auto_now=True)
app/admin.py
--- 
+++ 
@@ -1,3 +1,6 @@
 from django.contrib import admin
+from app.models import Article, UserProfile

-# Register your models here.
+
+admin.site.register(Article)
+admin.site.register(UserProfile)
djangocourse/settings.py
--- 
+++ 
@@ -81,6 +81,8 @@
     }
 }

+AUTH_USER_MODEL = "app.UserProfile"
+

 # Password validation
 # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators