-
Notifications
You must be signed in to change notification settings - Fork 27
Newsletters models and migration files added. #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: newsletters
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('profiles', '0002_auto_20170918_2235'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='department', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('department', models.CharField(max_length=50)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='newsletters', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('title', models.CharField(max_length=25)), | ||
('year', models.DateField()), | ||
('paper', models.FileField(upload_to=b'newsletters')), | ||
('created_at', models.DateTimeField()), | ||
('modified_at', models.DateTimeField()), | ||
('department', models.ForeignKey(to='newsletters.department')), | ||
('uploaded_by', models.ForeignKey(to='profiles.FacultyDetail')), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.contrib.auth.models import User | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
|
||
class department(models.Model): | ||
''' | ||
Stores the detail of department linked with its newsletters | ||
''' | ||
department = models.CharField(max_length=50, | ||
blank=False, | ||
null=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need this explicitly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay sir. I'll merge this into newsletters model itself. |
||
|
||
def __unicode__(self): | ||
return "%s" % (self.department) | ||
|
||
|
||
class newsletters(models.Model): | ||
''' | ||
Stores the pdfs of newsletters | ||
''' | ||
title = models.CharField(null=False, | ||
max_length=25) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shift this to the previous line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay sir. |
||
uploaded_by = models.ForeignKey(User) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay sir. Will add this. |
||
year = models.DateField() | ||
paper = models.FileField(upload_to="newsletters", | ||
blank=False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this |
||
null=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this. |
||
department = models.ForeignKey(department) | ||
created_at = models.DateTimeField() | ||
modified_at = models.DateTimeField() | ||
|
||
def create_newsletter(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please tell me the use case of this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sir, I had in mind of writing some test cases for this model but did not frame them. Will remove it for now and add this in a separate PR with test cases. |
||
self.created_at = timezone.now() | ||
self.modified_at = timezone.now() | ||
|
||
def modify_newsletter(self): | ||
self.modified_at = timezone.now() | ||
|
||
def __unicode__(self): | ||
return "%s" % (self.title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay sir. I'll shift this into newsletters model itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deshraj

Sir, I revised the model and felt we must keep it separate for easy management of newsletters. While designing this model I categorized all the newsletters into their respective departments. By having a separate model for department, we can easily link all the newsletters to a common department. Making it as an attribute in one model will dissolve the categories.
This categorization can be viewed in django admin-
Below screenshot displays all the departments which lists all the newsletters of that department.
Under any department, all it's newsletters can be managed this way-

Please sir let me know your thoughts over it. I'll make the changes accordingly. 🙂