Commit d5cfdde4ec07fd3976e8624c47b2595818864491

Authored by Gustavo Bernardo
1 parent 452de87f

Started news app and some adjusts iniciated

news/__init__.py 0 → 100644
news/admin.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.contrib import admin
  2 +
  3 +# Register your models here.
... ...
news/apps.py 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +from django.apps import AppConfig
  2 +
  3 +
  4 +class NewsConfig(AppConfig):
  5 + name = 'news'
... ...
news/forms.py 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +from django import forms
  2 +from django.utils.translation import ugettext_lazy as _
  3 +
  4 +from .models import News
  5 +
  6 +class NewsForm(forms.ModelForm):
  7 + class Meta:
  8 + model = News
  9 + fields = ['title','image','content']
  10 + widgets = {
  11 + 'content': forms.Textarea,
  12 + }
... ...
news/migrations/__init__.py 0 → 100644
news/models.py 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +from django.db import models
  2 +
  3 +# Create your models here.
  4 +from autoslug.fields import AutoSlugField
  5 +
  6 +from django.utils.translation import ugettext_lazy as _
  7 +from django.core.exceptions import ValidationError
  8 +
  9 +
  10 +def validate_img_extension(value):
  11 + valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png']
  12 +
  13 + if hasattr(value.file, 'content_type'):
  14 + if not value.file.content_type in valid_formats:
  15 + raise ValidationError(_('File not supported.'))
  16 +
  17 +class News(models.Model):
  18 + title = models.CharField( _("Name"), unique = True,max_length= 200)
  19 + slug = AutoSlugField(_("Slug"),populate_from='title',unique=True)
  20 + image = models.ImageField(verbose_name = _('News Image'), upload_to = 'news/', validators = [validate_img_extension])
  21 + content = models.TextField(_('Description'))
... ...
news/tests.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.test import TestCase
  2 +
  3 +# Create your tests here.
... ...
news/urls.py 0 → 100644
news/views.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.shortcuts import render
  2 +
  3 +# Create your views here.
... ...