from django.db import models
from PIL import Image
from lrntkr.managers import CourseManager
class University(models.Model):
name = models.CharField(max_length=70)
address = models.CharField(max_length=120,blank=True,null=True)
country = models.CharField(max_length=30)
website = models.URLField()
def __unicode__(self):
return (
self.name)
class Instructor(models.Model):
name = models.CharField(max_length=70)
specilist = models.CharField(max_length=120)
about = models.CharField(max_length=200,blank=True,null=True)
email = models.EmailField()
universities = models.ManyToManyField(University)
def __unicode__(self):
return
self.name
class Course(models.Model):
title = models.CharField(max_length=70)
stream = models.CharField(max_length=70)
universities = models.ManyToManyField(University)
instruct = models.ManyToManyField(Instructor)
description = models.CharField(max_length=70,blank=True, null=True)
start_date = models.CharField(max_length=30)
work_load = models.CharField(max_length=30)
logo = models.ImageField(upload_to='logos',blank=True,null=True)
intro = models.URLField(verify_exists = False, max_length = 225,blank=True,null=True)
initiative = models.URLField(verify_exists = False, max_length = 225,blank=True,null=True)
initiator = models.CharField(max_length=50,blank=True,null=True)
courseinfo = models.BooleanField(db_index=True,default=True)
objects = CourseManager()
def save(self, size=(200, 200)):
if not
self.id and not self.logo:
return
super(Course, self).save()
pw = self.logo.width
ph = self.logo.height
nw = size[0]
nh = size[1]
# only do this if the image needs resizing
if (pw, ph) != (nw, nh):
filename = str(self.logo.path)
image = Image.open(filename)
pr = float(pw) / float(ph)
nr = float(nw) / float(nh)
if pr > nr:
# photo aspect is wider than destination ratio
tw = int(round(nh * pr))
image = image.resize((tw, nh), Image.ANTIALIAS)
l = int(round(( tw - nw ) / 2.0))
image = image.crop((l, 0, l + nw, nh))
elif pr < nr:
# photo aspect is taller than destination ratio
th = int(round(nw / pr))
image = image.resize((nw, th), Image.ANTIALIAS)
t = int(round(( th - nh ) / 2.0))
print((0, t, nw, t + nh))
image = image.crop((0, t, nw, t + nh))
else:
# photo aspect matches the destination ratio
image = image.resize(size, Image.ANTIALIAS)
image.save(filename)
def __unicode__(self):
return self.title
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class Student(models.Model):
name = models.CharField(max_length=70)
birth_date = models.DateField(blank=True, null=True)
email_id = models.EmailField()
contact_no = models.IntegerField(blank=True,null=True)
address = models.CharField(max_length=120,blank=True, null=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
courses = models.ManyToManyField(Course)
def __unicode__(self):
return
self.name
hi, i have got one error during adding data in database though admin page, actually it was working fine, but i made some attributes optional, now it's generating error..
i m adding m models.py ,plz help me..
thanks in advance
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at
http://groups.google.com/group/django-users?hl=en.
For more options, visit
https://groups.google.com/groups/opt_out.