Пример #1
0
class AlternativeName(models.Model):
    name = models.CharField(max_length=256)
    language = models.CharField(max_length=100)
    is_preferred = models.BooleanField(default=False)
    is_short = models.BooleanField(default=False)
    is_colloquial = models.BooleanField(default=False)

    def __unicode__(self):
        return "%s (%s)" % (force_unicode(
            self.name), force_unicode(self.language))
Пример #2
0
                        class Student(models.Model):

                           sname   = models.CharField(max_length=20)

                           sgender = models.BooleanField(default=True)

                           sage    = models.IntegerField()

                           scontend= models.CharField(max_length=20)

                           isDelete= models.BooleanField(default=False)
                            # 关联外键
                           sgrade  =  models.ForeignKey("Grades")
Пример #3
0
class Cart(models.Model):
    creation_date = models.DateTimeField(verbose_name=_('creation date'))
    checked_out = models.BooleanField(default=False, verbose_name=_('checked out'))

    class Meta:
        verbose_name = _('cart')
        verbose_name_plural = _('carts')
        ordering = ('-creation_date',)

    def __unicode__(self):
        return unicode(self.creation_date)
Пример #4
0
                        class Grades(models.Model):

                           gname    =    models.CharField(max_length=20)   # 最长20个字节

                           gdate    =    models.DateTimeaField()    # 时间类型

                           ggirlnum =    models.IntegerField()   

                           gboynum  =    models.IntegerField()

                           isDelete =    models.BooleanField(default=False)      
Пример #5
0
class Profile(models.Model):
    """ Common profile model pieces. """
    data_manager = None

    date_added = models.DateTimeField(_('date added'), auto_now_add=True)
    date_verified = models.DateTimeField(_('date verified'),
                                         default=datetime.now)
    is_verified = models.BooleanField(default=False)

    class Meta:
        abstract = True

    def _get_data_item(self):
        # Find profile data for this profile id
        for network in self.data_manager.data:
            if network['id'] == self.network_id:
                return network
        return None

    data_item = property(_get_data_item)

    def _get_name(self):
        # Profile display name
        return self.data_item['name']

    name = property(_get_name)

    def _get_url(self):
        # Profile URL with username
        return self.data_item['url'] % self.username

    url = property(_get_url)

    def _get_icon_name(self):
        # Icon name
        return self.data_item['icon']

    icon_name = property(_get_icon_name)

    def _get_icon(self):
        # Icon URL or link to Google icon service
        if self.icon_name:
            print reverse('elsewhere_img', args=[self.icon_name])
            print self.icon_name
            return reverse('elsewhere_img', args=[self.icon_name])
        return GOOGLE_PROFILE_URL % self.url

    icon = property(_get_icon)
Пример #6
0
class User(models.Model):
    name = models.CharField(max_length=255)
    email = models.CharField(max_length=255, unique=True)
    password = models.CharField(max_length=60)
    last_4_digits = models.CharField(max_length=4)
    stripe_id = models.CharField(max_length=255)
    subscribed = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.name

    def set_password(self, clear_password):
        salt = bcrypt.gensalt(settings.BCRYPT_ROUNDS)
        self.password = bcrypt.hashpw(clear_password, salt)

    def check_password(self, clear_password):
        return bcrypt.hashpw(clear_password, self.password) == self.password
Пример #7
0
class Person(object):
    first_name = models.CharField(size=30, primary_key=True)
    last_name = models.CharField(size=30)
    age = models.IntegerField()
    dob = models.DatetimeField()
    isMale = models.BooleanField()
Пример #8
0
class Event(models.Model):
    class Meta:
        verbose_name = _('event')
        verbose_name_plural = _('events')
        ordering = ['-event_date', '-start_time', '-title']
        get_latest_by = 'event_date'
        permissions = (("change_author", ugettext("Change author")), )
        unique_together = ("event_date", "slug")

    def __unicode__(self):
        return _("%(title)s on %(event_date)s") % {
            'title': self.title,
            'event_date': self.event_date
        }

    @models.permalink
    def get_absolute_url(self):
        return ('agenda-detail', (), {
            'year': self.event_date.year,
            'month': self.event_date.month,
            'day': self.event_date.day,
            'slug': self.slug
        })

    objects = models.Manager()
    on_site = CurrentSiteManager()
    published = PublicationManager()

    # Core fields
    title = models.CharField(_('title'), max_length=255)
    slug = models.SlugField(_('slug'), db_index=True)

    event_date = models.DateField(_('date'))

    start_time = models.TimeField(_('start time'), blank=True, null=True)
    end_time = models.TimeField(_('end time'), blank=True, null=True)

    location = models.ForeignKey(Location, blank=True, null=True)

    description = models.TextField(_('description'))

    calendar = models.ForeignKey("Calendar",
                                 blank=True,
                                 null=True,
                                 related_name='events')

    # Extra fields
    add_date = models.DateTimeField(_('add date'), auto_now_add=True)
    mod_date = models.DateTimeField(_('modification date'), auto_now=True)

    author = models.ForeignKey(User,
                               verbose_name=_('author'),
                               db_index=True,
                               blank=True,
                               null=True)

    publish_date = models.DateTimeField(_('publication date'),
                                        default=datetime.now())
    publish = models.BooleanField(_('publish'), default=True)

    allow_comments = models.BooleanField(_('Allow comments'), default=True)

    sites = models.ManyToManyField(Site)

    def save(self):
        super(Event, self).save()
        if not settings.DEBUG:
            try:
                ping_google()
            except Exception:
                import logging
                logging.warn('Google ping on save did not work.')