class PGPKey(models.Model):
    key_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    fingerprint = models.CharField(max_length=128, default="NOT_SET")
    realname = models.CharField(max_length=128)
    email = models.EmailField(max_length=256, unique=True)
    password = models.CharField(max_length=256)
    created_by = models.ForeignKey(user_model, on_delete=models.SET(get_sentinel_user))
    created_date = models.DateTimeField(default=timezone.now)
    expire_date = models.DateTimeField(default=datetime.now() + timedelta(days=90))

    class Meta:
        db_table = 'pgp_keys'
        verbose_name_plural = 'pgp_keys'

    def __str__(self):
        """Return fingerprint when cast as string."""
        return self.fingerprint

    def save(self, *args, **kwargs):
        self.password = make_password(self.password)

        super().save(*args, **kwargs)
class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0001_initial'),
        ('projects', '0048_auto_20200731_1047'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='project',
            name='user',
        ),
        migrations.AddField(
            model_name='project',
            name='user_profile',
            field=models.ForeignKey(blank=True,
                                    null=True,
                                    on_delete=models.SET('deleted_user'),
                                    related_name='projects',
                                    to='profiles.UserProfile'),
        ),
    ]
class Face(models.Model):
    photo = models.ForeignKey(Photo,
                              related_name='faces',
                              blank=False,
                              null=False)
    image = models.ImageField(upload_to='faces')
    image_path = models.FilePathField()

    person = models.ForeignKey(Person,
                               on_delete=models.SET(get_unknown_person),
                               related_name='faces')
    person_label_is_inferred = models.NullBooleanField(db_index=True)

    location_top = models.IntegerField()
    location_bottom = models.IntegerField()
    location_left = models.IntegerField()
    location_right = models.IntegerField()

    encoding = models.TextField()

    def __str__(self):
        return "%d" % self.id
Exemple #4
0
class AaSrpRequestComment(models.Model):
    """
    SRP Request Comments model
    """

    comment = models.TextField(null=True, blank=True)

    comment_type = models.CharField(
        max_length=19,
        choices=AaSrpRequestCommentType.choices,
        default=AaSrpRequestCommentType.COMMENT,
    )

    creator = models.ForeignKey(
        User,
        related_name="+",
        null=True,
        blank=True,
        default=None,
        on_delete=models.SET(get_sentinel_user),
    )

    srp_request = models.ForeignKey(
        AaSrpRequest,
        related_name="srp_request_comments",
        null=True,
        blank=True,
        default=None,
        on_delete=models.CASCADE,
    )

    class Meta:
        """
        Meta definitions
        """

        default_permissions = ()
        verbose_name = _("SRP Request Comment")
        verbose_name_plural = _("SRP Request Comments")
class CurrentContest(models.Model):
    main = models.ForeignKey(Contest,
                             on_delete=models.SET('get_latest_contest'))

    class Meta:
        verbose_name_plural = 'Current Contest'

    @property
    def get_current_poster(self):
        return settings.STATIC_URL + self.main.poster.name

    @classmethod
    def load(cls):
        obj, created = cls.objects.get_or_create(pk=1)
        return obj

    def save(self, *args, **kwargs):
        self.pk = 1
        super(CurrentContest, self).save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        pass
Exemple #6
0
class Snippet(models.Model):
    title = models.CharField(max_length=255, blank=True,
                             null=True,
                             help_text='Optional title for the snippet')
    language = models.ForeignKey(to=Language,
                                 on_delete=models.SET('no language available'),
                                 related_name='snippets',
                                 help_text='Programming language of the snippet')
    code = models.TextField(help_text='The code of the snippet')
    description = models.TextField(help_text='Optional description of the code',
                                   blank=True, null=True)
    copies = models.PositiveIntegerField(default=0,
                                         help_text='Number of times a user has copied the snippet to clipboard')
    tags = models.ManyToManyField(to=Tag, related_name='snippets', blank=True)
    public = models.BooleanField(default=False,
                                 help_text='True if the user wants the snippet to be visible to other users')
    owner = models.ForeignKey(to=User, on_delete=models.CASCADE,
                              related_name='snippets',
                              help_text='The user who owns this snippet')
    parent = models.ForeignKey(to='Snippet', on_delete=models.SET_NULL,
                               related_name='children',
                               null=True, blank=True,
                               help_text='The snippet this is forked from')

    def __str__(self):
        return f"{self.owner.username}'s {self.language.name} snippet:{self.id}"

    @property
    def preview(self):
        limit = 15
        count = 0
        code = self.code
        preview = ''
        for char in code:
            if char == '\n':
                count += 1
            if count < limit:
                preview += char
        return preview
Exemple #7
0
class Forum(models.Model):
    category = models.ForeignKey(Category,
                                 on_delete=models.SET_NULL,
                                 blank=True,
                                 null=True)
    title = models.CharField(max_length=80)
    description = models.TextField(blank=True, default='')
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET(get_sentinel_user),
    )

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        """
        Returns the url to access a particular book instance.
        """
        return reverse('forum-detail', args=[str(self.id)])
Exemple #8
0
class Product(models.Model):
    name = models.CharField(max_length=65)
    company = models.CharField(max_length=255)
    price = models.DecimalField(max_digits=6, decimal_places=2)
    value = models.DecimalField(max_digits=6, decimal_places=2)
    date = models.DateTimeField(auto_now_add=True, blank=True)
    description = models.TextField(max_length=100000, default='')
    type = models.ForeignKey(Type, on_delete=models.SET(None))
    quantity = models.IntegerField(default=1)
    how_to_use = models.TextField(default='')
    front_images = models.ImageField(upload_to=filepath_front_images,
                                     default=None,
                                     validators=[validate_image])
    projects = models.ForeignKey(Project, on_delete=models.SET_NULL, null=True)
    city = models.ForeignKey(City,
                             on_delete=models.SET_NULL,
                             default=None,
                             null=True,
                             related_name='city_product')

    def __str__(self):
        return self.name
Exemple #9
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('users', '0017_donation_donor'),
    ]

    operations = [
        migrations.CreateModel(
            name='Notification',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('supported_projects_mobile', models.BooleanField(default=True)),
                ('supported_projects_email', models.BooleanField(default=True)),
                ('general_mobile', models.BooleanField(default=True)),
                ('general_email', models.BooleanField(default=True)),
                ('exciting_projects_mobile', models.BooleanField(default=True)),
                ('exciting_projects_email', models.BooleanField(default=True)),
                ('username', models.ForeignKey(on_delete=models.SET('team member not set'), to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
Exemple #10
0
class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Company',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50, unique=True)),
                ('emp_num', models.IntegerField(default=0)),
                ('adress', models.CharField(max_length=50)),
            ],
        ),
        migrations.CreateModel(
            name='Partnership',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(default='-', max_length=50, unique=True)),
                ('com_1', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='first_partner', to='crs_api.company', to_field='name')),
                ('com_1_employees', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='first_partner_employees', to='crs_api.company', to_field='name')),
                ('com_2', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='second_partner', to='crs_api.company', to_field='name')),
                ('com_2_employees', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='second_partner_employees', to='crs_api.company', to_field='name')),
            ],
        ),
        migrations.CreateModel(
            name='Employee',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('username', models.CharField(max_length=50)),
                ('age', models.IntegerField()),
                ('position', models.CharField(choices=[('1', 'general manager'), ('2', 'manager'), ('3', 'department head'), ('4', 'employee')], default='-', max_length=50)),
                ('company', models.ForeignKey(blank=True, null=True, on_delete=models.SET('-'), related_name='employees', to='crs_api.company', to_field='name')),
            ],
        ),
    ]
Exemple #11
0
class NoteComment(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    parent = models.ForeignKey('self',
                               on_delete=models.CASCADE,
                               blank=True,
                               null=True,
                               related_name="reply_set")
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             on_delete=models.SET(get_sentinel_user))
    note = models.ForeignKey(Note,
                             related_name='comments',
                             on_delete=models.CASCADE)
    body = models.CharField(max_length=2000)
    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.body

    class Meta:
        db_table = "note_comment"
        ordering = ["date_created"]
Exemple #12
0
class Person(models.Model):
    KIND_CHOICES = (('USER', 'User Labelled'), ('CLUSTER', 'Cluster ID'),
                    ('UNKNOWN', 'Unknown Person'))
    name = models.CharField(blank=False, max_length=128)
    kind = models.CharField(choices=KIND_CHOICES, max_length=10)
    mean_face_encoding = models.TextField()
    cluster_id = models.IntegerField(null=True)
    account = models.OneToOneField(User,
                                   on_delete=models.SET(get_deleted_user),
                                   default=None,
                                   null=True)

    def __str__(self):
        return "%d" % self.id

    def _update_average_face_encoding(self):
        encodings = []
        faces = self.faces.all()
        for face in faces:
            r = base64.b64decode(face.encoding)
            encoding = np.frombuffer(r, dtype=np.float64)
            encodings.append(encoding)
        mean_encoding = np.array(encodings).mean(axis=0)
        self.mean_face_encoding = base64.encodebytes(mean_encoding.tostring())

    def get_photos(self, owner):
        faces = list(
            self.faces.prefetch_related(
                Prefetch(
                    'photo',
                    queryset=Photo.objects.exclude(image_hash=None).filter(
                        hidden=False,
                        owner=owner).order_by('-exif_timestamp').only(
                            'image_hash', 'exif_timestamp', 'favorited',
                            'owner__id', 'public',
                            'hidden').prefetch_related('owner'))))

        photos = [face.photo for face in faces if hasattr(face.photo, 'owner')]
        return photos
Exemple #13
0
class Signature(TimeStampedModel):
    """Signature model to track who signs for checks"""

    first_name = models.CharField(max_length=40)
    last_name = models.CharField(max_length=40)
    signature = models.TextField()
    related_check = models.OneToOneField('checks.Check',
                                         related_name="signature",
                                         on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.SET(deleted_user))

    def save(self, *args, **kwargs):
        """Override save method to set the associated check's picked_up field to true"""
        from specialhandling.checks.models import Check
        # pylint: disable=E1101
        update_check = Check.objects.get(id=self.related_check.id)
        update_check.picked_up = True
        update_check.save()
        super().save(*args, **kwargs)  # Call the "real" save() method.

    def __str__(self):
        return '%d - %s, %s' % (self.id, self.last_name, self.first_name)
Exemple #14
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('pjtmgmt', '0005_mntgroupuser'),
    ]

    operations = [
        migrations.CreateModel(
            name='SqlcProject',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_dt', models.DateTimeField(default=datetime.datetime.now)),
                ('project_nm', models.CharField(default='프로젝트 명칭', max_length=255)),
                ('project_desc', models.TextField(default='프로젝트 설명')),
                ('sta_eff_dt', models.CharField(max_length=8)),
                ('end_eff_dt', models.CharField(max_length=8)),
                ('owner', models.ForeignKey(on_delete=models.SET(pjtmgmt.models.get_sentinel_user), to=settings.AUTH_USER_MODEL)),
                ('prod_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pjtmgmt.SqlcProd')),
            ],
        ),
    ]
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Client',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('nomer_zayavki', models.IntegerField(unique=True)),
                ('date_posted',
                 models.DateTimeField(default=django.utils.timezone.now)),
                ('fio_klienta', models.CharField(default='', max_length=100)),
                ('summa_zayavki', models.IntegerField()),
                ('purpose', models.CharField(max_length=200)),
                ('srok_kredita', models.IntegerField()),
                ('product', models.CharField(max_length=20)),
                ('zalog', models.CharField(max_length=20)),
                ('status', models.CharField(max_length=20)),
                ('istochnik', models.CharField(max_length=20)),
                ('reason', models.CharField(max_length=200, null=True)),
                ('date_refuse', models.DateTimeField(null=True)),
                ('protokol_number',
                 models.CharField(max_length=20, null=True, unique=True)),
                ('credit_user',
                 models.ForeignKey(
                     on_delete=models.SET('Удаленный пользователь'),
                     to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
Exemple #16
0
class Migration(migrations.Migration):

    dependencies = [
        ('auctions', '0009_auctionitem_current_price'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='auctionitem',
            name='category',
        ),
        migrations.AddField(
            model_name='auctionitem',
            name='category',
            field=models.ForeignKey(default=None, on_delete=models.SET(None), to='auctions.category'),
        ),
        migrations.AlterField(
            model_name='auctionitem',
            name='current_price',
            field=models.DecimalField(decimal_places=2, default=0, max_digits=10, validators=[django.core.validators.MinValueValidator(0.01)]),
        ),
    ]
Exemple #17
0
class Place(models.Model):
    name = models.CharField(max_length=100,
                            null=False,
                            blank=False,
                            verbose_name=_("Name"))
    organization = models.ForeignKey(Organization,
                                     on_delete=models.CASCADE,
                                     null=False)
    owner = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, null=True)

    description = MarkdownField(verbose_name=_("Place description"),
                                null=False,
                                blank=False,
                                default="")

    type = models.ForeignKey(PlaceType,
                             verbose_name=_('Type'),
                             null=False,
                             on_delete=models.SET(PlaceType.get_other_place))

    slug = AutoSlugField(populate_from='name', default='', unique=True)
    # geolocation is provided by the AddressField
    address = AddressField(null=False,
                           blank=False,
                           default="",
                           verbose_name=_("Postal address"))
    picture = models.ImageField(verbose_name=_('Image'), upload_to='places/')

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def get_absolute_url(self):
        return reverse('place_detail', args=(
            self.pk,
            self.slug,
        ))

    def __str__(self):
        return self.name
Exemple #18
0
class Profile(models.Model):
    first_name = models.CharField('First name', max_length=50)
    middle_name = models.CharField('Middle name', max_length=50)
    last_name = models.CharField('Last name', max_length=50)
    position = models.CharField('Position', max_length=100)
    employment_date = models.DateField('Employment date')
    salary = models.FloatField('Salary')
    chief = models.ForeignKey('self',
                              verbose_name='Chief',
                              null=True,
                              blank=True,
                              related_name='employees',
                              on_delete=models.SET(get_chief))

    def get_full_name(self):
        middle_name = self.middle_name.split(' ')[0]
        return '{} {} {}'.format(self.first_name, middle_name, self.last_name)

    @property
    def get_middle_name(self):
        middle_name = self.middle_name.split(' ')[0]
        return '{}'.format(middle_name)
Exemple #19
0
class Student(models.Model):
    EXPERIENCE_TRAINEE = 0
    EXPERIENCE_JUNIOR = 1
    EXPERIENCE_MIDDLE = 2
    EXPERIENCE_SENIOR = 3

    EXPERIENCE_CHOICES = ((EXPERIENCE_TRAINEE, 'TRAINEE'), (EXPERIENCE_JUNIOR,
                                                            'JUNIOR'),
                          (EXPERIENCE_MIDDLE, 'MIDDLE'), (EXPERIENCE_SENIOR,
                                                          'SENIOR'))

    firstname = models.CharField(max_length=255,
                                 null=False,
                                 default="",
                                 verbose_name="Имя")
    lastname = models.CharField(max_length=255,
                                null=False,
                                default="",
                                verbose_name="Фамилия")
    age = models.IntegerField(null=False, default=1, verbose_name="Возраст")
    group = models.ForeignKey(Group,
                              on_delete=models.SET("Without Group"),
                              verbose_name="Группа",
                              related_name='students')
    # group = models.ManyToManyField(
    #     Group,
    #     blank=True,
    #     verbose_name="Группа"
    # )
    phone = PhoneField(blank=True, help_text='Contact phone number')
    experience = models.PositiveSmallIntegerField(choices=EXPERIENCE_CHOICES,
                                                  default=0)

    def __str__(self):
        return f'{self.firstname} {self.lastname} {self.age}'

    class Meta:
        verbose_name = "Студент"
        verbose_name_plural = "Студенты"
Exemple #20
0
class Profile(models.Model):
    user = models.OneToOneField(
        'authentication.User',
        on_delete=models.CASCADE,
        db_index=True,
    )
    active_plan = models.ForeignKey(Plan,
                                    on_delete=models.SET(get_sentinel_plan),
                                    default=get_sentinel_plan)

    connected_devices = models.IntegerField(_('connected_devices'), default=0)

    amount_consumed_down = models.BigIntegerField(_('amount_consumed_down'), default=0)
    amount_consumed_up = models.BigIntegerField(_('amount_consumed_up'), default=0)


    @classmethod
    def get_by_username(self, username):
        return self.objects.select_related('user').get(
            user__username=username)

    @property
    def amount_consumed(self):
        "Returns total amount of bandwith which is consumed."
        return self.amount_consumed_down + self.amount_consumed_up

    def add_device(self):
        if self.connected_devices <= self.active_plan.max_connected_devices:
            self.connected_devices += 1

    def remove_device(self):
        if 0 < self.connected_devices:
            self.connected_devices -= 1

    def remove_all_devices(self):
        self.connected_devices = 0

    def __str__(self):
        return self.user.username
Exemple #21
0
class Beer(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET(get_sentinel_user),
    )
    name = models.CharField(max_length=100, unique=True)
    description = models.TextField(blank=True, default='')
    abv = models.DecimalField(max_digits=5, decimal_places=2)
    webpage = models.CharField(max_length=100, blank=True, default='')
    logo = models.CharField(max_length=100, blank=True, default='')
    brewery = models.ForeignKey(
        'Brewery',
        on_delete=models.CASCADE,
    )
    beertype = models.ForeignKey(
        'BeerType',
        on_delete=models.CASCADE,
    )

    class Meta:
        ordering = ('created', )
Exemple #22
0
class Post(models.Model):
    title = models.CharField(max_length=125)
    content = models.TextField()

    author = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET(get_sentinel_user),
        default=1
    )
    url_name = models.SlugField(unique=True, default=get_unique_post_slug)

    time_created = models.DateTimeField(auto_now=False, auto_now_add=True)
    last_updated = models.DateTimeField(auto_now=True, auto_now_add=False)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('blog:detail', kwargs={'url_name':self.url_name})

    class Meta:
        ordering = ['-time_created', '-last_updated']
Exemple #23
0
class Event(models.Model):

    ELIGIBLE_CHOICES = models.TextChoices('eligible_user_type',
                                          'STUDENT TEACHER').choices
    STATUS_CHOICES = models.TextChoices('status',
                                        'ACTIVE CLOSED COMPLETED').choices

    name = models.CharField(max_length=50)
    description = models.TextField()
    sport = models.ForeignKey(Sport,
                              on_delete=models.SET('Deleted Sport'),
                              related_name='events')
    fee = models.IntegerField(default=0)
    venue = models.CharField(max_length=50)
    date_time = models.DateTimeField(auto_now=False,
                                     auto_now_add=False)  # Use timeone instead
    reg_close_date = models.DateField(auto_now=False, auto_now_add=False)
    eligible_user_type = models.CharField(choices=ELIGIBLE_CHOICES,
                                          max_length=10)

    status = models.CharField(choices=STATUS_CHOICES, max_length=10)
    curr_round = models.IntegerField(default=0)
    participants = models.ManyToManyField(CustomUser, blank=True)

    class Meta:
        verbose_name = "Event"
        verbose_name_plural = "Events"

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse("event_detail", kwargs={"pk": self.pk})

    def complete(self):
        print(self.status)
        self.status = 'COMPLETED'
        print(self.name)
        print(self.status)
Exemple #24
0
class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('wagtailstreamforms', '0006_emailform_to_addresses_help_text'),
    ]

    operations = [
        migrations.AddField(
            model_name='baseform',
            name='content_type',
            field=models.ForeignKey(
                null=True,
                on_delete=models.SET(wagtailstreamforms.models.form.
                                     get_default_form_content_type),
                related_name='streamforms',
                to='contenttypes.ContentType',
                verbose_name='content type'),
            preserve_default=False,
        ),
        migrations.RunPython(set_content_types)
    ]
class Migration(migrations.Migration):

    dependencies = [
        ('feedback', '0001_initial'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='category',
            name='id',
        ),
        migrations.AlterField(
            model_name='category',
            name='name',
            field=models.CharField(max_length=20, primary_key=True, serialize=False),
        ),
        migrations.AlterField(
            model_name='feedback',
            name='category',
            field=models.ForeignKey(default=None, on_delete=models.SET('Others'), to='feedback.Category'),
        ),
    ]
Exemple #26
0
class PrintRequest(models.Model):
    username = models.ForeignKey(get_user_model(),
                                 related_name='users',
                                 on_delete=models.SET(get_sentinel_user))
    req_time = models.DateTimeField(auto_now_add=True)
    source = models.FileField("Source",
                              upload_to=get_file_path,
                              validators=[validate_size, validate_type])
    printed = models.BooleanField(default=False)

    def __str__(self):
        return self.req_time.strftime("%d/%m/%Y, %H:%M:%S")

    def filename(self):
        return os.path.basename(self.source.name)

    def link(self):
        return self.source.url

    def printlink(self):
        return '/print/' + self.username.username + '/' + os.path.basename(
            self.source.name)
Exemple #27
0
class ContentBase(models.Model):
    is_active = models.BooleanField(default=1, verbose_name="Actif")
    created_on = models.DateTimeField(auto_now_add=True)
    updated_on = models.DateTimeField(auto_now=True)
    #Both author & updated_by managed by django-author
    author = models.ForeignKey(User,
                               related_name="%(class)s_author",
                               blank=True,
                               null=True,
                               on_delete=models.SET(1))
    updated_by = models.ForeignKey(User,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL)

    class Meta:
        abstract = True

    def is_active_value(self):
        return self.is_active

    is_active_value.boolean = True
Exemple #28
0
class Article(models.Model):
    title = models.CharField(max_length=150, unique=True)
    slug = models.SlugField(unique=True)
    thumbnail = models.ImageField(upload_to='thumbnails')
    category = models.ManyToManyField(Category)
    tags = TaggableManager()
    author = models.ForeignKey(User, on_delete=models.SET(2))
    summary = models.TextField(max_length=160)
    body = RichTextUploadingField()
    ip_address = models.GenericIPAddressField(blank=True, null=True)
    is_posted = models.BooleanField(default=False)
    is_featured = models.BooleanField(default=False)
    views = models.IntegerField(default=0)
    date_posted = models.DateTimeField(auto_now_add=True)
    date_updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title

    def snippet(self):
        return self.summary

    def get_absolute_url(self):
        return reverse('author:article-detail', kwargs={'pk': self.pk})

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):

        if not self.id:
            # Newly created object, so set slug
            self.slug = slugify(self.title)

        super().save()
        img = Image.open(self.thumbnail.path)
        img = img.resize((800, 400))
        img.save(self.thumbnail.path)
Exemple #29
0
class Migration(migrations.Migration):

    dependencies = [
        ('card', '0011_merge_20210104_1502'),
    ]

    operations = [
        migrations.AlterField(
            model_name='card',
            name='created_at',
            field=models.DateTimeField(blank=True,
                                       default='2021-01-04 15:02:58'),
        ),
        migrations.AlterField(
            model_name='card',
            name='prev',
            field=models.OneToOneField(null=True,
                                       on_delete=models.SET(None),
                                       related_name='next',
                                       to='card.card'),
        ),
    ]
Exemple #30
0
class Estudiante(models.Model):

    name = models.CharField(max_length=100, null=False)
    lastname = models.CharField(max_length=100, null=False)
    age = models.IntegerField(null=False)
    gender = models.CharField(max_length=100, null=False)  #Genero
    address = models.CharField(max_length=250, null=False)
    enrollment = models.IntegerField(null=False)  #Matricula
    subject = models.CharField(max_length=100, null=False)
    phoneNumber = models.IntegerField(null=False)
    birthday = models.DateField(default=timezone.now)
    profesorId = models.ForeignKey(Profesor, on_delete=models.SET(-1))
    #delete = models.BooleanField(default = True)
    created = models.DateTimeField(default=timezone.now)

    #edited = models.DateTimeField(blank=True, null=True, default=None)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'Estudiante'