Skip to content

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

Open
wants to merge 3 commits into
base: newsletters
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions newsletters/migrations/0001_initial.py
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')),
],
),
]
Empty file.
41 changes: 41 additions & 0 deletions newsletters/models.py
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,
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.
image

Under any department, all it's newsletters can be managed this way-
image

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

null=False)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shift this to the previous line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sir.

uploaded_by = models.ForeignKey(User)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add related_model attribute here.

Copy link
Member Author

Choose a reason for hiding this comment

The 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

null=False)
Copy link
Member

Choose a reason for hiding this comment

The 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please tell me the use case of this method?

Copy link
Member Author

Choose a reason for hiding this comment

The 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)