Commit 77b7d1ee authored by Isaiah Flores's avatar Isaiah Flores

Update widget_group3/widget_group3/models.py

parent a4e83b42
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
class Department(models.Model):
dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model): class WidgetUser(models.Model):
id_num = models.IntegerField() id_num = models.IntegerField()
first_name = models.CharField(max_length=100) first_name = models.CharField(max_length=90)
middle_name = models.CharField(max_length=100) middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100)
email = models.EmailField() email = models.EmailField()
department = models.ForeignKey(Department, on_delete=models.CASCADE, default=1)
def __str__(self):
return '{}, {} {}: {}, {}'.format(self.last_name, self.first_name, self.middle_name, self.id_num, self.email)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('widget_user', args=[(self.full_name)]) return reverse('widget_user', args=[(self.full_name)])
...@@ -17,14 +22,6 @@ class WidgetUser(models.Model): ...@@ -17,14 +22,6 @@ class WidgetUser(models.Model):
def full_name(self): def full_name(self):
return '{} {} {}'.format(self.first_name, self.middle_name, self.last_name) return '{} {} {}'.format(self.first_name, self.middle_name, self.last_name)
class Department(models.Model):
dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100)
widget_user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class Announcement(models.Model): class Announcement(models.Model):
announcement_title= models.CharField(max_length=50) announcement_title= models.CharField(max_length=50)
announcement_body = models.CharField(max_length=200) announcement_body = models.CharField(max_length=200)
...@@ -45,6 +42,7 @@ class Post(models.Model): ...@@ -45,6 +42,7 @@ class Post(models.Model):
post_body = models.CharField(max_length=100) post_body = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True, editable=False) pub_date = models.DateTimeField(auto_now_add=True, editable=False)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
# author_name = WidgetUser.objects.get(fk=author).full_name()
def __str__(self): def __str__(self):
return '{} by {} dated {}:<br> {}'.format(self.post_title, self.author.full_name(), self.pub_date, self.post_body) return '{} by {} dated {}:<br> {}'.format(self.post_title, self.author.full_name(), self.pub_date, self.post_body)
......
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