Initialized Lab 4 from Lab 3 due to reformatting pc; added forms.py

parent 30710e36
from django import forms
from .models import Author, Books
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = '__all__'
class BookForm(forms.ModelForm):
class Meta:
model = Books
fields = '__all__'
\ No newline at end of file
from django.db import models from django.db import models
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=255) first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255)
...@@ -10,6 +11,7 @@ class Author(models.Model): ...@@ -10,6 +11,7 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return "{} {}".format(self.first_name, self.last_name) return "{} {}".format(self.first_name, self.last_name)
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment