示例#1
0
class Image(TimeStampedModel):
    file = models.ImageField()
    location = models.CharField(max_length=140)
    caption = models.TextField()
    creator = models.ForeignKey(
        user_model.User,
        on_delete=models.CASCADE,
        null=True,
        related_name='images'
    )
    tags = TaggableManager()

    @property
    def like_count(self):
        return self.likes.all().count()

    @property
    def comment_count(self):
        return self.comments.all().count()

    @property
    def natural_time(self):
        return naturaltime(self.created_at)

    def __str__(self):
        return "{location} - {caption}".format(
            location=self.location, caption=self.caption
        )

    class Meta:
        ordering = ['-created_at']
示例#2
0
class Supplier(models.Model):
    supplier = models.CharField(verbose_name=_('Supplier Name'), max_length=32)
    default_markup = models.PositiveIntegerField(
        verbose_name=_('Default Markup'), default=0, max_length=255)
    description = models.TextField(blank=True, verbose_name=_('Description'))
    company = models.CharField(verbose_name=_('Company'), max_length=32)
    first_name = models.CharField(verbose_name=_('First Name'), max_length=32)
    last_name = models.CharField(verbose_name=_('Last Name'), max_length=32)
    archived = models.BooleanField(default=False)
    created = models.DateTimeField(editable=False)
    phone = models.CharField(verbose_name=_('Phone'),
                             max_length=60,
                             null=True,
                             blank=True)
    mobile = models.CharField(verbose_name=_('Mobile Phone'),
                              max_length=60,
                              null=True,
                              blank=True)
    fax = models.CharField(verbose_name=_('Fax'),
                           max_length=60,
                           null=True,
                           blank=True)
    email = models.EmailField(unique=True,
                              verbose_name=_('Email'),
                              null=False,
                              blank=False)
    website = models.URLField(verbose_name=_('Website'), null=True, blank=True)
    street = models.CharField(verbose_name=_('Street'),
                              max_length=32,
                              null=True,
                              blank=True)
    suburb = models.CharField(verbose_name=_('Suburb'),
                              max_length=32,
                              null=True,
                              blank=True)
    city = models.CharField(verbose_name=_('City'),
                            max_length=32,
                            null=True,
                            blank=True)
    postcode = models.CharField(verbose_name=_('Post Code'),
                                max_length=8,
                                null=True,
                                blank=True)
    state = models.CharField(verbose_name=_('State'),
                             max_length=2,
                             choices=STATE_CHOICES,
                             null=True,
                             blank=True)
    country = CountryField(blank_label='(select a country)')

    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)

    def save(self, *args, **kwargs):
        """
        On save, update timestamps
        """
        if not self.id:
            self.created = datetime.today()
        return super(Supplier, self).save(*args, **kwargs)
示例#3
0
class Post(models.Model):
    title = models.CharField(max_length=100, default='sample title')
    content = models.TextField()
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    date_posted = models.DateTimeField(default=datetime.now)

    def __str__(self):
        return self.title
示例#4
0
class UserAddress(AnonymizerModel):
    street = models.TextField(max_length=128, null=True, blank=True)
    city = models.CharField(max_length=64, null=True, blank=True)

    class AnonymizerMeta:
        anonymizer_fields = ['street']

    def __str__(self):
        return f'<UserAddress PK:{self.pk} | Street: {self.street} | City: {self.city}>'
示例#5
0
class Article(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    title = models.CharField(max_length=100, blank=False, default='')
    content = models.TextField()

    category_id = models.ForeignKey(Category, related_name='article_cat', on_delete=models.CASCADE)
    created_by_user_id = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='created_by_user_id',
                                           on_delete=models.SET_NULL, blank=True, null=True)

    class Meta:
        ordering = ('-updated_at', )

    def __str__(self):
        return self.title
示例#6
0
class Comment(TimeStampedModel):
    creator = models.ForeignKey(
        user_model.User,
        on_delete=models.CASCADE,
        null=True
    )
    image = models.ForeignKey(
        Image,
        on_delete=models.CASCADE,
        related_name="comments",
        null=True
    )

    message = models.TextField()

    def __str__(self):
        return self.message
示例#7
0
class Professor(AbstractBaseUser):
    nome = models.CharField(max_length=120)
    ra = models.IntegerField(unique=True)
    password = models.TextField()
    status = models.BooleanField(default=True)
    email = models.CharField(max_length=80, blank=True, null=True)
    perfil = models.CharField(max_length=1, blank=True, default='P')
    celular = models.CharField(max_length=11, blank=True, null=True)

    USERNAME_FIELD = 'ra'
    REQUIRED_FIELDS = ['nome', 'email']

    def __str__(self):
        return self.nome + '(' + str(self.ra) + ')'

    class Meta:
        managed = False
        db_table = 'professor'
示例#8
0
class Customer(models.Model):
    first_name = models.CharField(max_length=32)
    last_name = models.CharField(max_length=32)
    email = models.EmailField(null=True, blank=True)
    phone = models.CharField(max_length=32, null=True, blank=True)
    profile_key = models.CharField(max_length=32, null=True, blank=True)
    address = models.CharField(max_length=32, null=True, blank=True)
    rewards_points = models.IntegerField(null=True, blank=True)
    account_number = models.CharField(max_length=64, blank=True)
    notes = models.TextField(null=True, blank=True)
    archived = models.BooleanField(default=False)
    created = models.DateTimeField(editable=False)
    city = models.CharField(verbose_name=_('City'),
                            max_length=58,
                            null=True,
                            blank=True)
    state = models.CharField(verbose_name=_('State'),
                             max_length=2,
                             choices=STATE_CHOICES,
                             null=True,
                             blank=True)
    zipcode = models.CharField(verbose_name=_('Zip code'),
                               max_length=8,
                               null=True,
                               blank=True)
    group = models.ForeignKey(CustomerGroup,
                              blank=True,
                              null=True,
                              related_name='taskin_group')

    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)

    def save(self, *args, **kwargs):
        """
        On save, update timestamps
        """
        if not self.id:
            self.created = datetime.today()
        return super(Customer, self).save(*args, **kwargs)

    def get_full_name(self):
        return self.first_name + ' ' + self.last_name
示例#9
0
class Usuario(AbstractBaseUser):
    ra = models.IntegerField('RA', unique=True)
    nome = models.CharField(max_length=120)
    email = models.CharField(max_length=80)
    password = models.TextField()
    status = models.BooleanField('Status', default=True)
    perfil = models.CharField('Perfil', max_length=1, default='C')

    # criando qual o campo de identificação do 'USUARIO'
    USERNAME_FIELD = 'ra'

    #colocando com campo de inserção obrigatorio no 'BANCO'
    REQUIRED_FIELDS = [
        'nome',
        'email',
    ]

    objects = UsuarioManager()

    # criando a função de apresentação do 'USUARIO'
    def __str__(self):
        return self.nome

    # criando as funcoes de como ira mostra o nome do 'USUARIO' nos Templates

    #  Funções 'OBRIGATORIAS pelo DJANGO
    def get_full_name(self):
        return self.nome

    def get_short_name(self):
        return self.nome

    def has_perm(self, perm, obj=None):
        return True

    def has_module_perms(self, app_label):
        return True

    @property
    def is_staff(self):
        return self.perfil == 'C'
示例#10
0
class PersonalInformation(models.Model):
    user = models.OneToOneField(User,
                                related_name='personal_information',
                                on_delete=models.CASCADE)
    place_birth = models.CharField(max_length=255, null=True, blank=True)
    birth_date = models.DateField(null=True, blank=True)
    has_children = models.BooleanField(null=True, blank=True, default=None)
    number_of_children = models.IntegerField(null=True,
                                             blank=True,
                                             default=None)
    gender = models.ForeignKey(Gender,
                               related_name='gender',
                               null=True,
                               blank=True,
                               on_delete=models.CASCADE)
    marital_status = models.ForeignKey(MaritalStatus, on_delete=models.CASCADE)
    marital_status_description = models.TextField(null=True, blank=True)
    height = models.FloatField(null=True, blank=True)
    weight = models.FloatField(null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True, null=True)
    updated_at = models.DateTimeField(auto_now=True, null=True)
示例#11
0
class Employee(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True,
                              verbose_name=_('Email'),
                              null=False,
                              blank=False)
    photo = models.ImageField(upload_to='employee_photo/',
                              verbose_name=_('P'),
                              blank=True,
                              default='employee_photo/def.jpg')
    name = models.CharField(verbose_name=_('Name'), max_length=32)
    address = models.CharField(verbose_name=_('Address'),
                               max_length=32,
                               null=True,
                               blank=True)
    address2 = models.CharField(verbose_name=_("Address2"),
                                null=True,
                                blank=True,
                                max_length=32)
    city = models.CharField(verbose_name=_('City'),
                            max_length=32,
                            null=True,
                            blank=True)
    state = models.CharField(verbose_name=_('State'),
                             max_length=2,
                             choices=STATE_CHOICES,
                             null=True,
                             blank=True)
    zipcode = models.CharField(verbose_name=_('Zip code'),
                               max_length=8,
                               null=True,
                               blank=True)
    phone = models.CharField(verbose_name=_('Phone'),
                             max_length=60,
                             null=True,
                             blank=True)
    pin = models.IntegerField(verbose_name=_('Pin'), unique=True, null=True)
    role = models.IntegerField(verbose_name=_('Role'), choices=ROLES)
    vein_string = models.TextField(blank=True, verbose_name=_('Vein String'))
    hourly_rate = models.DecimalField(blank=True,
                                      null=True,
                                      verbose_name=_('Hourly Rate'),
                                      decimal_places=2,
                                      max_digits=5)
    archived = models.BooleanField(default=False)
    store = models.ForeignKey(Store,
                              verbose_name='Store',
                              blank=True,
                              null=True)

    USERNAME_FIELD = 'email'

    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    created = models.DateTimeField(editable=False)

    objects = EmployeeManager()

    def __unicode__(self):
        return u"%s" % self.name

    def get_full_name(self):
        return self.name

    def get_short_name(self):
        return self.name

    def check_is_owner(self):
        return self.role == ROLES[0][0]

    def return_id(self):
        return self.id

    def save(self, *args, **kwargs):
        ''' On save, update timestamps '''
        if self.photo:
            try:
                self.photo = resize_image(self.photo,
                                          newsize=EMPLOYEE_PHOTO_SIZE)
            except:
                logger.exception("Error resizing image for product %s" %
                                 self.pk)
                pass
        if not self.id:
            self.created = datetime.today()
        return super(Employee, self).save(*args, **kwargs)
示例#12
0
class UserSecretData(AnonymizerModel):
    super_secret_data = models.TextField(null=True, blank=True)