示例#1
0
class RegIncident(models.Model):
    CompleteDate = models.DateField(verbose_name="Date")
    Application = models.CharField(verbose_name="Application Name",
                                   max_length=30)
    SealID = models.CharField(verbose_name="SealID", max_length=10)
    Severity = models.CharField(verbose_name="Severity", max_length=4)
    TicketNum = models.CharField(verbose_name="Ticket",
                                 unique=True,
                                 max_length=13)
    StartTime = models.TimeField(verbose_name="Start Hour")
    EndTime = models.TimeField(verbose_name="End Hour")
    IssueDesc = ck.RichTextField(verbose_name="Issue description")
    ReportTo = models.CharField(verbose_name="Report to regulator?",
                                max_length=3)
    Impact = ck.RichTextField(verbose_name="Impact")
    RegBy = models.ForeignKey(User,
                              verbose_name="Registered by",
                              on_delete=models.PROTECT)
    ReportedBy = models.CharField(verbose_name="Reported by")
    Country = countries.CountryField(verbose_name="Country")
    Extras = models.FileField(verbose_name="Another extras",
                              upload_to="ExtrasEv")

    #Checar si se necesita relación de muchos a muchos entre la tabla de usuarios default y esta tabla.

    class Meta():
        verbose_name = "Incident"
        verbose_name_plural = "Incidents"

    def __str__(self):
        return self.TicketNum
示例#2
0
class Episode(models.Model):
    title = models.CharField(max_length=10, unique=False, default='Episode 1')
    subtitle = models.CharField(max_length=50, default='Starfield')
    image = models.ImageField(upload_to='Episode/', default='default.jpg')
    description = fields.RichTextField(blank=True, null=True)
    reference = fields.RichTextField(blank=True, null=True)
    link_to_github_code = models.CharField(max_length=255, blank=True)
    related_season = models.ForeignKey(Season, on_delete=models.CASCADE)
    slug = models.SlugField(unique=True, blank=True)

    # Some Common Methods
    def save(self, *args, **kwargs):
        self.slug = slugify(f'{self.title} of '
                            f'{self.related_season.title} of '
                            f'{self.related_season.related_babe.title}')
        super().save(*args, **kwargs)

    def __str__(self):
        return self.slug

    def get_class_name(self):
        return self.__class__.__name__

    # Project Design
    def get_object_list_url(self):
        return reverse('ProjectDesign:episode-list-page')

    def get_object_create_url(self):
        return reverse('ProjectDesign:episode-create-page')

    def get_object_retrieve_url(self):
        return reverse('ProjectDesign:episode-retrieve-page',
                       kwargs={
                           'slug': self.slug
                       })

    def get_object_update_url(self):
        return reverse('ProjectDesign:episode-update-page',
                       kwargs={
                           'slug': self.slug
                       })

    def get_object_delete_url(self):
        return reverse('ProjectDesign:episode-delete-page',
                       kwargs={
                           'slug': self.slug
                       })

    # Project Model
    def get_episode_page_url(self):
        return reverse('ProjectModel:episode-page',
                       kwargs={
                           'slug': self.slug
                       })
示例#3
0
class Page(models.Model):
    title = models.CharField(max_length=200, verbose_name="título")
    content = fields.RichTextField(verbose_name="contenido")
    ordering = models.SmallIntegerField(default=0, verbose_name="orden")
    created = models.DateTimeField(auto_now_add=True,
                                   verbose_name="fecha de creación")
    updated = models.DateTimeField(auto_now=True,
                                   verbose_name="fecha de actualización")

    class Meta:
        verbose_name = "página"
        verbose_name_plural = "páginas"
        ordering = ['ordering', 'title']

    def __str__(self):
        return self.title

    def get_slug(self):
        return slugify(self.title)

    def get_absolute_url(self):
        return reverse('pages:page',
                       kwargs={
                           'pk': self.id,
                           'slug': self.get_slug()
                       })
示例#4
0
class Post(models.Model):
    title = models.CharField(max_length=200, verbose_name="título")
    content = fields.RichTextField(verbose_name="contenido")
    image = models.ImageField(blank=True,
                              null=True,
                              upload_to='blog',
                              verbose_name="imagen")
    published = models.DateTimeField(default=now,
                                     verbose_name="fecha de publicación")
    created = models.DateTimeField(auto_now_add=True,
                                   verbose_name="fecha de creación")
    updated = models.DateTimeField(auto_now=True,
                                   verbose_name="fecha de actualización")
    author = models.ForeignKey(User,
                               on_delete=models.CASCADE,
                               verbose_name="autor")
    categories = models.ManyToManyField(Category,
                                        related_name="get_posts",
                                        verbose_name="categorías")

    class Meta:
        verbose_name = "posteo"
        verbose_name_plural = "posteos"
        ordering = ['-created']

    def __str__(self):
        return self.title
示例#5
0
class Babe(models.Model):
    title = models.CharField(max_length=50, unique=True, default='Python Babe')
    subtitle = models.CharField(max_length=50, default='I love long hair & I wear glasses!')
    image = models.ImageField(upload_to='Babe/', default='default.jpg')
    description = fields.RichTextField(blank=True, null=True)
    related_home = models.ForeignKey(Home, on_delete=models.CASCADE)
    slug = models.SlugField(unique=True, blank=True)

    # Some Common Methods
    def save(self, *args, **kwargs):
        self.slug = slugify(f"{self.title}")
        super().save(*args, **kwargs)

    def __str__(self):
        return self.slug

    def get_class_name(self):
        return self.__class__.__name__

    # ProjectDesign
    def get_object_list_url(self):
        return reverse('ProjectDesign:babe-list-page')

    def get_object_create_url(self):
        return reverse('ProjectDesign:babe-create-page')

    def get_object_retrieve_url(self):
        return reverse('ProjectDesign:babe-retrieve-page',
                       kwargs={
                           'slug': self.slug
                       })

    def get_object_update_url(self):
        return reverse('ProjectDesign:babe-update-page',
                       kwargs={
                           'slug': self.slug
                       })

    def get_object_delete_url(self):
        return reverse('ProjectDesign:babe-delete-page',
                       kwargs={
                           'slug': self.slug
                       })

    # ProjectModel
    def get_babe_page_url(self):
        return reverse('ProjectModel:babe-page',
                       kwargs={
                           'slug': self.slug
                       })

    # ProjectReal
    def get_real_babe_page_url(self):
        return reverse('ProjectReal:babe-page',
                       kwargs={
                           'slug': self.slug
                       })
示例#6
0
class Topic(models.Model):
    """ A topic or question the user wants to talk about. """
    text = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now_add=True)
    body_text = fields.RichTextField()
    owner = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        """ Return a string representation of the model. """
        return self.text
示例#7
0
class Season(models.Model):
    title = models.CharField(max_length=10, unique=False, default='Season 1')
    subtitle = models.CharField(max_length=50, default='Python Library p5')
    image = models.ImageField(upload_to='Season/', default='default.jpg')
    description = fields.RichTextField(blank=True, null=True)
    related_babe = models.ForeignKey(Babe, on_delete=models.CASCADE)
    slug = models.SlugField(unique=True, blank=True)

    # Some Common Methods
    def save(self, *args, **kwargs):
        self.slug = slugify(f'{self.title} of {self.related_babe.title}')
        super().save(*args, **kwargs)

    def __str__(self):
        return self.slug

    def get_class_name(self):
        return self.__class__.__name__

    # Project Design
    def get_object_list_url(self):
        return reverse('ProjectDesign:season-list-page')

    def get_object_create_url(self):
        return reverse('ProjectDesign:season-create-page')

    def get_object_retrieve_url(self):
        return reverse('ProjectDesign:season-retrieve-page',
                       kwargs={
                           'slug': self.slug
                       })

    def get_object_update_url(self):
        return reverse('ProjectDesign:season-update-page',
                       kwargs={
                           'slug': self.slug
                       })

    def get_object_delete_url(self):
        return reverse('ProjectDesign:season-delete-page',
                       kwargs={
                           'slug': self.slug
                       })

    # Project Model
    def get_season_page_url(self):
        return reverse('ProjectModel:season-page',
                       kwargs={
                           'slug': self.slug
                       })
示例#8
0
class Author(models.Model):

    name = models.CharField(max_length=45)
    country = models.CharField(max_length=45, choices=COUNTRY_CHOICES)
    works_at = models.CharField(max_length=48)
    description = fields.RichTextField(blank=True, null=True)
    image = models.ImageField(blank=True, upload_to='Blog/images', null=True)
    email = models.EmailField(blank=True, null=True)
    facebook_url = models.URLField(blank=True, null=True)
    instagram_url = models.URLField(blank=True, null=True)
    twitter_url = models.URLField(blank=True, null=True)

    def __str__(self):
        return self.name
示例#9
0
class Entry(models.Model):
    """ An entry for a topic. """
    topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
    text = fields.RichTextField()
    date_added = models.DateTimeField(auto_now_add=True)
    owner = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = 'entries'

    def __str__(self):
        """ Return a string representation of the model. """
        if len(self.text) > 50:
            return f'{self.text[:50]}...'
        return self.text
示例#10
0
class Page(models.Model):
    title = models.CharField(max_length=200, verbose_name="título")
    content = fields.RichTextField(verbose_name="contenido")
    ordering = models.SmallIntegerField(default=0, verbose_name="orden")
    created = models.DateTimeField(auto_now_add=True,
                                   verbose_name="fecha de creación")
    updated = models.DateTimeField(auto_now=True,
                                   verbose_name="fecha de actualización")

    class Meta:
        verbose_name = "página"
        verbose_name_plural = "páginas"
        ordering = ['ordering', 'title']

    def __str__(self):
        return self.title
示例#11
0
class News(models.Model):
    STATUS_CHOICES = (('draft', 'Draft'), ('published', 'Published'))
    title = models.CharField(max_length=250)
    content = fields.RichTextField()
    timestamp = models.DateTimeField(auto_now_add=True)
    updated = models.DateField(auto_now=True)
    # published
    status = models.CharField(max_length=9,
                              choices=STATUS_CHOICES,
                              default='draft')

    def __str__(self):
        return self.title

    class Meta:
        ordering = ["-timestamp", "-updated"]
示例#12
0
class Service(models.Model):
    title = models.CharField(max_length=200, verbose_name="título")
    subtitle = models.CharField(max_length=200, verbose_name="subtítulo")
    content = fields.RichTextField(verbose_name="contenido")
    image = models.ImageField(upload_to="services", verbose_name="imagen")
    created = models.DateTimeField(auto_now_add=True,
                                   verbose_name="fecha de creación")
    updated = models.DateTimeField(auto_now=True,
                                   verbose_name="fecha de actualización")

    class Meta:
        verbose_name = "servicio"
        verbose_name_plural = "servicios"
        ordering = ['-created']

    def __str__(self):
        return self.title
示例#13
0
class PageModel(models.Model):
    title = models.CharField(max_length=50, verbose_name="Title")
    content = ck.RichTextField(verbose_name="Content")
    slug = models.CharField(unique=True,
                            max_length=150,
                            verbose_name="URL amigable")
    order = models.IntegerField(default=0, verbose_name="Order")
    visible = models.BooleanField(verbose_name="Visible?")
    created_at = models.DateTimeField(auto_now_add=True,
                                      verbose_name="Created at")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="Updated at")

    class Meta():
        verbose_name = "URL page"
        verbose_name_plural = "URL pages"

    def __str__(self):
        return self.title
示例#14
0
class Blog(models.Model):
    heading = models.CharField(max_length=100)
    publish_date = models.DateTimeField()
    content = fields.RichTextField()
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    tags = models.ManyToManyField(Tag, related_name='blogs')
    read = models.IntegerField(default=0)
    front_img = models.ImageField(blank=True,
                                  upload_to='Blog/images',
                                  null=True)

    def was_published_recently(self):
        return self.publish_date >= timezone.now() - datetime.timedelta(days=2)

    class Meta:
        ordering = ['-id']

    def __str__(self):
        return self.heading
示例#15
0
class Youtuber(models.Model):

    crew_choices = (
        ('solo', 'solo'),
        ('small', 'small'),
        ('large', 'large'),
    )

    camera_choices = (
        ('canon', 'canon'),
        ('nikon', 'nikon'),
        ('sony', 'sony'),
        ('red', 'red'),
        ('fuji', 'fuji'),
        ('other', 'other'),
    )

    category_choices = (
        ('code', 'code'),
        ('mobile_review', 'mobile_review'),
        ('vlogs', 'vlogs'),
        ('comdey', 'comedy'),
        ('gaming', 'gaming')
    )

    name = models.CharField(max_length=255)
    price = models.IntegerField()
    photo = models.ImageField(upload_to='media/youtubers/%y/%m/%d')
    video_url = models.CharField(max_length=255)
    description = fields.RichTextField()
    city = models.CharField(max_length=255)
    age = models.IntegerField()
    crew = models.CharField(max_length=255, choices=crew_choices)
    camera_type = models.CharField(max_length=255, choices=camera_choices)
    subs_count = models.CharField(max_length=255)
    category = models.CharField(max_length=255, choices=category_choices)
    is_featured = models.BooleanField()
    category = models.CharField(max_length=255, choices=category_choices)
    django_created_at = models.DateField(default=datetime.now, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateField(auto_now=True)
示例#16
0
class Post(models.Model):
    title = models.CharField(max_length=255)
    content = fields.RichTextField()
    pub_date = models.DateTimeField(default=timezone.now, editable=False)
    mod_date = models.DateTimeField(blank=True, null=True, editable=False)
    image = models.ImageField(upload_to='movieblog/posts/images/', blank=True, null=True)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('posts:post_details', kwargs={'pk': str(self.pk)})

    def save(self, *args, **kwargs):
        if self.image:
            self.image = compress_image(self.image)
        super().save(*args, **kwargs)

    class Meta:
        ordering = ['-pub_date']
class BlogPost(EnabledMixin, TimeStampMixin, models.Model):
    """Model to describe a blog post."""
    class Status:
        """Blog statuses."""

        DRAFT = 0
        PUBLISHED = 1

        CHOICES = (
            (DRAFT, _('Draft')),
            (PUBLISHED, _('Published')),
        )

    title = models.CharField(verbose_name=_('Title'),
                             max_length=255,
                             help_text=_('Title of the blog post.'))

    content = fields.RichTextField(verbose_name=_('Content'),
                                   blank=True,
                                   null=True,
                                   help_text=_('Content of the blog post.'))

    slug = models.SlugField(verbose_name=_('Slug'),
                            unique=True,
                            max_length=255,
                            default=None,
                            null=True,
                            blank=True,
                            help_text=_('URL slug of the blog post.'))

    author = models.ForeignKey(verbose_name=_('Author'),
                               to=settings.AUTH_USER_MODEL,
                               on_delete=models.deletion.SET_NULL,
                               related_name='blogs',
                               null=True,
                               blank=True,
                               help_text=_('The author of this blog post.'))

    status = models.IntegerField(verbose_name=_('Status'),
                                 choices=Status.CHOICES,
                                 default=Status.DRAFT,
                                 help_text=_('The status of the blog post.'))

    published = models.DateTimeField(verbose_name=_('Published'),
                                     null=True,
                                     blank=True,
                                     help_text=_('Date blog post published.'))

    class Meta:
        """Metaclass for Blog model."""

        app_label = 'blog'
        verbose_name = _('Blog post')
        verbose_name_plural = _('Blog posts')

    @property
    def is_published(self):
        """
        Return whether this blog post is published.

        :return: whether this blog post is published
        :rtype: bool
        """
        return self.status == self.Status.PUBLISHED and \
            self.published is not None

    def publish(self, user, commit=True):
        """
        Publish this blog post.

        Performs the following actions:
        - sets status to published
        - sets published date to now
        - sets author to one supplied

        :param user: user publishing this blog post
        :type user: authentication.models.user.User
        :param commit: whether to save to database
        :type commit: bool
        """
        self.author = user
        self.published = now()
        self.status = self.Status.PUBLISHED

        if commit:
            self.save(update_fields=['author', 'published', 'status'])
示例#18
0
class Page(TimeStampMixin, EnabledMixin, models.Model):
    """Model to describe a static web page."""

    url = models.CharField(
        verbose_name=_('URL'),
        max_length=255,
        db_index=True,
        unique=True,
        help_text=_(
            'The relative url path describing what page this model represents.'
            'e.g. /about/'
        )
    )
    title = models.CharField(
        verbose_name=_('Title'),
        max_length=255,
        help_text=_('The page title')
    )
    content = fields.RichTextField(
        verbose_name=_('Content'),
        blank=True,
        null=True,
        help_text=_('The content to be displayed on the static page.')
    )
    template_name = models.CharField(
        verbose_name=_('Template name'),
        max_length=255,
        blank=True,
        null=True,
        help_text=_(
            'The relative path describing which template to use. If not set '
            'will default to /staticpages/page.html'
        )
    )

    class Meta:
        """Metadata for StaticPage model."""

        app_label = 'staticpages'
        verbose_name = _('Page')
        verbose_name_plural = _('Pages')

    @classmethod
    def get_page(cls, url):
        """
        Get the Page object provided a url.

        :param url: static page url
        :type url: str
        :return: the Page
        :rtype: staticpages.models.page.Page
        :raises: staticpages.exceptions.PageNotFound
        """
        clean_url = cls.process_url(url)
        try:
            page = cls.objects.get(url=clean_url)
        except cls.DoesNotExist:
            raise PageNotFound

        return page

    @staticmethod
    def process_url(url):
        """
        Process the static page URL ensuring it starts and ends with '/'.

        :param url: the provided static page URL
        :type url: str
        :return: the final static page URL with starting and trailing '/'
        """
        if not url.startswith('/'):
            url = '/' + url

        if not url.endswith('/'):
            url += '/'

        return url
示例#19
0
class Anuncio(models.Model):
    id_usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE)
    descripcion = fields.RichTextField(max_length=200, default="")
    imagen = models.ImageField(upload_to="fotosAnuncios/", blank=True)
    fecha_anuncio = models.DateField(auto_now=True)